0

我在 Silverlight4 VS 2010 中工作。我在我的 .xaml 文件中放置了一个 CheckBox。我需要它的 DataContextChanged 事件。但不幸的是我没有找到它。

这是我的复选框:

<CheckBox x:Name="chkRegion" Content="{Binding name}" Click="CheckBox_Click" ></CheckBox>

您能否帮我在 SL 4 VS 2010 中找到 DataContextChanged。

谢谢,拉杰比尔

4

1 回答 1

1

实现一个转换器(它只是一个从 IValueConverter 派生并实现接口方法的简单类)

public class ChangeIsCheckedValConverter : IValueConverter
{
    public object Convert(object value,
                          Type targetType,
                          object parameter,
                          System.Globalization.CultureInfo culture)
    {
        if (value != null)
        {

//这里的值是你绑定到 Checkbox 的 DataContext 的对象;//根据绑定到复选框的值返回布尔值(真或假)

    }

    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 .

然后使用此转换器,其中您的复选框在数据模板中定义如下: //首先定义键如下:

 <converters:VisibilityConverter x:Key="changeConverter" />

<CheckBox x:Name="chkRegion" Content="{Binding name}" IsChecked={Binding ,Converter={StaticResource changeConverter}}"} Click="CheckBox_Click" ></CheckBox>
于 2013-01-14T07:09:21.880 回答