当我更改datacontext时,Twoway绑定崩溃了

时间:2012-08-08 22:18:16

标签: c# wpf xaml data-binding telerik

我正在使用twoway绑定动态更改我的一个用户控件的颜色并设置初始选定的颜色。它的结构如下(简化方式):

<RadGridView x:Name="T" ItemsSource="{Binding storage, Mode=OneWay}">
    <GridViewColumn>
        <GridViewColumn.Template>
            <ColorPicker SelectedColor="{Binding Color, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        </...>
    </...>
</...>

关联的C#代码:

void func(object sender) {
    this.DataContext = sender;
}

当我尝试更改GridView IF的DataContext时,我得到一个nullpointer异常,并且只有GridView中有元素。有没有办法绕过改变具有twoway绑定的gridview的源?

最佳, 金

0 个答案:

没有答案