Articles in categories

Articles

Simple wpf statusbar

Here's my simple wpf statusbar. It contains one large textblock for showing messages and two smaller textarea's for showing some other texts. You can also change the fontcolor of the large textblock to show a difference in the messages.

I'm planning on expanding the statusbar and adding an icon (error, exclamation mark, check sign) in front of the main textblock so it's more visible what kind of message is shown.

Screenshots:

The xaml:

<UserControl x:Class="WpfStatusbar.StatusbarControl"
						 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
						 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
						 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
						 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
						 mc:Ignorable="d"
						 d:DesignHeight="25"
						 d:DesignWidth="700"
						 MinHeight="25"
						 x:Name="Statuslogbar">
	<UserControl.Resources>
		<LinearGradientBrush x:Key="GradientBrush"
												 StartPoint="0,0"
												 EndPoint="0,1">
			<GradientStop Color="LightGray"
										Offset="0.0" />
			<GradientStop Color="White"
										Offset="0.2" />
			<GradientStop Color="#ffb2d0f8"
										Offset="0.7" />
			<GradientStop Color="SteelBlue"
										Offset="1.0" />
		</LinearGradientBrush>
	</UserControl.Resources>
	<StatusBar Background="{StaticResource GradientBrush}">
		<StatusBar.ItemsPanel>
			<ItemsPanelTemplate>
				<Grid>
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto" />
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="*" />
						<ColumnDefinition Width="Auto" />
						<ColumnDefinition Width="Auto" />
						<ColumnDefinition Width="Auto" />
						<ColumnDefinition Width="Auto" />
					</Grid.ColumnDefinitions>
				</Grid>
			</ItemsPanelTemplate>
		</StatusBar.ItemsPanel>
		<StatusBarItem HorizontalAlignment="Stretch"
									 HorizontalContentAlignment="Stretch">
			<Border BorderThickness="1"
							BorderBrush="Black"
							Background="White">
				<TextBlock Text="{Binding Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
									 Foreground="{Binding TextColorMessage}"
									 Background="White"
									 Margin="2" />
			</Border>
		</StatusBarItem>
		<Separator Grid.Column="1" />
		<StatusBarItem Grid.Column="2"
									 HorizontalAlignment="Right">
			<TextBlock Text="{Binding Path=DatabaseName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
		</StatusBarItem>
		<Separator Grid.Column="3" />
		<StatusBarItem Grid.Column="4"
									 HorizontalAlignment="Right">
			<TextBlock Text="{Binding Path=ComputerName}" />
		</StatusBarItem>
	</StatusBar>
</UserControl>

The ViewModel:

using System;
using System.Windows;
using System.Windows.Media;
using RealityFightingMembersApp.Helpers;

namespace StatusBar.ViewModel
{
  public class StatusBarViewModel: Notifier
  {
    public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(StatusBarViewModel), new UIPropertyMetadata("This is some message..."));
    public string Message
    {
      get { return (string)GetValue(MessageProperty); }
      set { SetValue(MessageProperty, value); }
    }

    public static readonly DependencyProperty DatabaseNameProperty = DependencyProperty.Register("DatabaseName", typeof(string), typeof(StatusBarViewModel), new UIPropertyMetadata(Environment.UserName));
    public string DatabaseName
    {
      get { return (string)GetValue(DatabaseNameProperty); }
      set { SetValue(DatabaseNameProperty, value); }
    }

    public static readonly DependencyProperty ComputerNameProperty = DependencyProperty.Register("ComputerName", typeof(string), typeof(StatusBarViewModel), new UIPropertyMetadata(Environment.MachineName));
    public string ComputerName
    {
      get { return (string)GetValue(ComputerNameProperty); }
      set { SetValue(ComputerNameProperty, value); }
    }

    public static readonly DependencyProperty TextColorMessageProperty = DependencyProperty.Register("TextColorMessage", typeof(SolidColorBrush), typeof(StatusBarViewModel), new UIPropertyMetadata(new SolidColorBrush(Colors.Black)));
    public SolidColorBrush TextColorMessage
    {
      get { return (SolidColorBrush)GetValue(TextColorMessageProperty); }
      set { SetValue(TextColorMessageProperty, value); }
    }
  }
}

It's a pretty basic and simple statusbar, but it does what I need it to do. If I update the statusbar I'll update my post.