I have a UserControl named StatusIndicator, with a Dependecy Property on
it, which has a PropertyChangedCallback I need, when the property
changes to change Visual State.
I have a GameState class with a
CurrentName property, which is bound to my UserControl's dependecy
property. It implements INotifyPropertyChange as well, and contains
these lines:
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)); } }
|
Unfortunatelly
PropertyChanged
is
always null, and I am unable to use my callback. The statically
initialized currentName value is set correctly, but later changes does
not affect the view.
I use StatusIndicator in the MainWindow.xaml:
<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 >
|
It is a project just to learn and try out things, but i would be glad if someone could help me.