【问题标题】:String to Image WPF Converter字符串到图像 WPF 转换器
【发布时间】:2010-11-24 14:57:34
【问题描述】:

如何在 WPF 中编写转换器以在 WPF 中显示四个状态图标,在我的项目中,我计划根据某些条件显示以下四个状态 1) 红点图标 - 未保存的数据 2) 绿点图标 - 保存成功 3) 白点图标或无图标 - 窗口已成功初始化并且没有未保存的数据。 4) 错误图标 - 保存数据时出现错误。

任何帮助将不胜感激,在此先感谢。

【问题讨论】:

  • 您的意思是如何更改窗口标题中显示的图标或仅显示点?

标签: c# wpf image data-binding converter


【解决方案1】:

如果要更改窗口图标,最简单的方法是创建所有图标并将它们保存为资源,然后使用以下命令进行更改:

Uri iconUri = new Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);

如果您只想在表单上显示点,请绘制一个圆圈并使用 yourCircle.Fill(newColor) 更改其颜色

这个例子来自msdn:

要画一个圆,请指定一个椭圆 其 Width 和 Height 值是 相等。

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;
        }
    }
}

【讨论】:

  • 非常感谢,按照建议我会画圆并改变它的颜色。
猜你喜欢
  • 1970-01-01
  • 2013-05-16
  • 2012-07-22
  • 2017-06-15
  • 2023-03-28
  • 2014-05-23
  • 2014-10-29
  • 1970-01-01
  • 2018-09-07
相关资源
最近更新 更多