I have a very simple WPF Application which has a slider and a button. I am trying to bind one of the properties in my class to the value of the slider and displaying the value in a messagebox whenever the button is clicked.
I have a property called BattingForm in my Player class
<Window.Resources>
<local:Player x:Key="_batsman" x:Name="_batsman"
BattingForm="{Binding Path=Value, ElementName=Form}">
</local:Player>
</Window.Resources>
<Slider Maximum="1" LargeChange="0.25" Value="0.25" Name="Form"/>
And inside the Player Class, the property is as follows.
public double BattingForm
{
get { return (double)GetValue(BattingFormProperty); }
set { SetValue(BattingFormProperty, value); }
}
public static readonly DependencyProperty BattingFormProperty =
DependencyProperty.Register("BattingForm", typeof(double), typeof(Player));
And in the MainWindow.xaml.cs inside the buttonclick event, I try to access it as follows -
Player batsman = FindResource("_batsman") as Player;
if(batsman!=null)
{
MessageBox.Show(batsman.BattingForm.ToString());
}
In the MessageBox it only shows 0, not the actual value of the Slider.