【问题标题】:WPF DataGrid CheckBoxColumn binding mode = TwoWay errorWPF DataGrid CheckBoxColumn 绑定模式 = TwoWay 错误
【发布时间】:2015-09-15 10:10:56
【问题描述】:

这是我的代码

<DataGrid.Columns>
    <DataGridTemplateColumn Header="" Width="30" IsReadOnly="False">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <CheckBox  IsChecked="{Binding Path = chk, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
        <DataGridTemplateColumn.CellStyle>
            <Style TargetType="{x:Type DataGridCell}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">
                            <Grid Background="{TemplateBinding Background}">
                                <ContentPresenter VerticalAlignment="Center"
                          HorizontalAlignment="Center" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </DataGridTemplateColumn.CellStyle>
    </DataGridTemplateColumn>

我有一个例外 绑定类型 TwoWay OneWayToSource 或不能使用只读属性“chk”类型“System.Data.DataRowView”。

当我做mode = OneWay时,一切都好。但是我需要改变目标对象和源对象

【问题讨论】:

    标签: c# wpf datagrid


    【解决方案1】:

    您绑定到 ComboBox "chk" 的属性没有实现 "set",因此它只有 get 它被视为 readonly 。实现set并调用INotifyPropertyChanged接口通知属性变化。

    【讨论】:

    • 您需要清楚自己的错误或 INotifyPropertyChanged 界面吗?
    • 您可以编辑您的代码并添加 C# 中的 chk 属性代码吗?当我告诉你错误的确切位置时,就会很容易理解。
    • 你一定要说我不使用mvvm。我是从数据集中获取数据的。
    • 如果您使用的是绑定,那么在 C# 中应该有一个属性可以放入 Xaml。发生的情况是,当 C# 属性发生任何更改时,相同的更改会反映在 UI 上,因为它绑定到 WPF 控件。请通过以下链接。 wpf-tutorial.com/data-binding/introduction
    猜你喜欢
    • 2014-08-08
    • 2019-07-27
    • 2015-07-25
    • 1970-01-01
    • 2011-09-18
    • 2016-07-16
    • 2011-08-10
    • 2012-05-12
    • 2023-04-10
    相关资源
    最近更新 更多