I am working in Silverlight4 VS 2010.I have placed a CheckBox in my .xaml file. I need it's DataContextChanged event. But unfortunately i didn't find it.
Here is my CheckBox :
<CheckBox x:Name="chkRegion" Content="{Binding name}" Click="CheckBox_Click" ></CheckBox>
Could you please help me in to find DataContextChanged in SL 4 VS 2010.
Thanks, Rajbir
Implement an Converter (its just a simple class which gets derived from IValueConverter and implement the interface methods)
public class ChangeIsCheckedValConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) {
//value here is the object which you are binding to the DataContext of Checkbox ; //return the bool (true or false) based on your valued binded to your checkbox
} public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; }
You will have to add the name space of you newly implemnted converter whereever you will want to use .
Then use this converter where your checkbox is defined in datatemplate as below : //First define the key as below :
<converters:VisibilityConverter x:Key="changeConverter" />
<CheckBox x:Name="chkRegion" Content="{Binding name}" IsChecked={Binding ,Converter={StaticResource changeConverter}}"} Click="CheckBox_Click" ></CheckBox>