views:

431

answers:

1

How to code a converter in WPF to display four status icons in WPF, In my project I am planning to display following four status based on certain conditions 1) Red Dot icon - Unsaved data 2) Green Dot icon - Save successful 3) White Dot icon OR No icon - window has Initialized successfully and there is no unsaved data. 4) Error icon - There were errors while saving data.

Any help would be highly appreciated, thanks in advance.

+1  A: 

If you want to change the window icon the simpliest way is to create all icons and save them as resource and then change it with:

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

If you want just to display dots on your form you draw a circle and change its color with yourCircle.Fill(newColor)

This example is from msdn:

To draw a circle, specify an Ellipse whose Width and Height values are equal.

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;
        }
    }
}
Svetlozar Angelov
Thanks a lot, As Suggested I will draw circle and change its color.
Nadeem