WPF DataGridCell IsReadOnly通过XAML取决于属性

时间:2013-01-30 14:04:27

标签: wpf datagrid readonly-attribute

我需要根据属性在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是一个布尔属性,位于datagrid中显示的对象内部,但我编写的代码不起作用,而如果我将IsreadOnly设置为true则可以正常工作。

我做错了什么? 谢谢

1 个答案:

答案 0 :(得分:0)

你打电话给OnPropertyChanged(“FL_COMMON”);在setter?

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

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