如何在 WPF 中编写转换器以在 WPF 中显示四个状态图标,在我的项目中,我计划根据某些条件显示以下四个状态 1)红点图标 - 未保存的数据 2)绿点图标 - 保存成功 3)白点图标或无图标 - 窗口已成功初始化并且没有未保存的数据。4) 错误图标 - 保存数据时出现错误。
任何帮助将不胜感激,在此先感谢。
如何在 WPF 中编写转换器以在 WPF 中显示四个状态图标,在我的项目中,我计划根据某些条件显示以下四个状态 1)红点图标 - 未保存的数据 2)绿点图标 - 保存成功 3)白点图标或无图标 - 窗口已成功初始化并且没有未保存的数据。4) 错误图标 - 保存数据时出现错误。
任何帮助将不胜感激,在此先感谢。
如果要更改窗口图标,最简单的方法是创建所有图标并将它们保存为资源,然后使用以下命令进行更改:
Uri iconUri = new Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);
如果您只想在表单上显示点,请绘制一个圆圈并使用 yourCircle.Fill(newColor) 更改其颜色
此示例来自msdn:
要绘制一个圆,请指定一个Width 和 Height 值相等的 Ellipse。
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace SDKSample
{
public partial class SetBackgroundColorOfShapeExample : Page
{
public SetBackgroundColorOfShapeExample()
{
// Create a StackPanel to contain the shape.
StackPanel myStackPanel = new StackPanel();
// Create a red Ellipse.
Ellipse myEllipse = new Ellipse();
// Create a SolidColorBrush with a red color to fill the
// Ellipse with.
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
// Describes the brush's color using RGB values.
// Each value has a range of 0-255.
mySolidColorBrush.Color = Color.FromArgb(255, 255, 255, 0);
myEllipse.Fill = mySolidColorBrush;
myEllipse.StrokeThickness = 2;
myEllipse.Stroke = Brushes.Black;
// Set the width and height of the Ellipse.
myEllipse.Width = 200;
myEllipse.Height = 100;
// Add the Ellipse to the StackPanel.
myStackPanel.Children.Add(myEllipse);
this.Content = myStackPanel;
}
}
}