【问题标题】:WPF DataGridCell IsReadOnly via XAML depending on a propertyWPF DataGridCell IsReadOnly 通过 XAML 取决于属性
【发布时间】:2013-01-30 14:04:26
【问题描述】:

我需要根据属性在 datagridCell 上设置 IsReadOnly 属性。

        <WPFCtrlDG:ExtDataGrid Grid.Row="2" 
                              InternalAddCommandHandling="False"
                              InternalDeleteCommandsHandling="False" 
                              ItemsSource="{Binding Path=Attributes, Mode=TwoWay}"
                              Command="{Binding Path=AttributesCommand}">
        <WPFCtrlDG:ExtDataGrid.Columns>
            <WPFCtrlDG:ExtDataGridTextColumn Header="Attribute" Tag="ID_ATTRIBUTE" Width="*" IsReadOnly="{Binding Path=FL_COMMON, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
            <WPFCtrlDG:ExtDataGridTextColumn Header="Value" Tag="ID_VALUE" Width="*" IsReadOnly="true"/>
        </WPFCtrlDG:ExtDataGrid.Columns>
    </WPFCtrlDG:ExtDataGrid>

public BindingList<SPC_SPL2_ATTRIBUTE> Attributes
    {
        get
        {
            if (Context.SPC_SPL2_ATTRIBUTE == null)
                Controller.Execute(delegate(IResult result)
                {
                    Dictionary<string, object> parameters = new Dictionary<string, object>();
                    parameters.Add("FL_ACTIVE", true);
                    parameters.Add("CD_SPL2", CurrentSPL2.CD_SPL2);

                    Model.Invalidate(typeof(SPC_SPL2_ATTRIBUTE), Filter.GENERIC<SPC_SPL2_ATTRIBUTE>(parameters, "ID_ATTRIBUTE"));
                    if (Model.Appendload(result) == false)
                        return false;

                    return result.Successful;
                });
            return Context.SPC_SPL2_ATTRIBUTE;
        }
        set { Context.SPC_SPL2_ATTRIBUTE = value; }
    }

FL_COMMON 是一个布尔属性,位于数据网格中显示的对象内,但我编写的代码不起作用,而如果我将 IsreadOnly 设置为 true,它会起作用。

我做错了什么? 谢谢

【问题讨论】:

  • 你能分享你绑定到 ItemSource 的类的结构吗?
  • 添加,它是一个从数据库加载的bindingList
  • FL_COMMONAttributes 属性相比在哪里?它应该是 Attributes 集合内项目的属性。

标签: wpf datagrid readonly-attribute


【解决方案1】:

你调用 OnPropertyChanged("FL_COMMON");在二传手?

包含 FL_COMMON 的类应实现 INotifyPropertyChanged,并且该属性应如下所示:

    private bool _FL_COMMON;
    public bool FL_COMMON
    {
        get { return _FL_COMMON; }
        set
        {
            _FL_COMMON = value;
            OnPropertyChanged("FL_COMMON");
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多