private static State current = State.Free;public State Current { get { return current; } set { current = value; CurrentName = current.ToString("G"); }}private static string currentName = State.Free.ToString("G");public string CurrentName { get { return currentName; } set { currentName = value; OnPropertyChanged("CurrentName"); }}public event PropertyChangedEventHandler PropertyChanged;private void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); }}
PropertyChanged
<Window x:Class="BattleHack.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:BattleHack.Managers" xmlns:ctrl="clr-namespace:BattleHack.Controls" xmlns:entity="clr-namespace:BattleHack.Entities" Title="BattleHack" Height="700" Width="500"><Window.Resources> <entity:GameState x:Key="GameState" /> <!-- ... --> </Window.Resources>...<DockPanel>...<ctrl:StatusIndicator Status="{Binding CurrentName, Source={StaticResource GameState}}" /> ...</DockPanel>
<Window x:Class="BattleHack.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:BattleHack.Managers" xmlns:ctrl="clr-namespace:BattleHack.Controls" xmlns:entity="clr-namespace:BattleHack.Entities" Title="BattleHack" Height="700" Width="500"><Window.Resources> <entity:GameState x:Key="GameState" /> <!-- ... --
>
</Window.Resources>...<DockPanel
...<ctrl:StatusIndicator Status="{Binding CurrentName, Source={StaticResource GameState}}" />
</DockPanel