1

我需要一些可编辑的 DataGrid 行,而另一些则不需要。

<DataGrid ItemsSource="{Binding Items.View}" AutoGenerateColumns="False" CanUserAddRows="False" >
    <DataGrid.Columns>
        <DataGridTextColumn IsReadOnly="True" Binding="{Binding Timestamp}" Width="Auto" >
            <DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{lex:Loc DateTime}" />
                </DataTemplate>
            </DataGridTextColumn.HeaderTemplate>
        </DataGridTextColumn>
        <DataGridTextColumn Binding="{Binding Value}" Width="Auto" >
            <DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{lex:Loc Value}" />
                </DataTemplate>
            </DataGridTextColumn.HeaderTemplate>
        </DataGridTextColumn>

我的项目中有一个属性 IsEditable。我喜欢这样的东西:

<DataGridTextColumn IsReadOnly="{Binding IsEditable, Converter={StaticResource InverseBooleanConverter}}" Binding="{Binding Value}" Width="Auto" >

与此同时,我知道这不可能那么容易。虽然我找不到适合我的问题的解决方案。

更新

不是那么重要,但为了更好地理解,我将从视图模型中添加更多数据。

private ObservableCollection<MeasuredValue> _last60values;
public ObservableCollection<MeasuredValue> Last60Values
{
    get { return _last60values; }
    set { _last60values = value; }
}

Items = new CollectionViewSource();
Items.Source = Last60Values;

和我的“测量值”

    namespace PQS.Model
    {
        public class MeasuredValue : CloneableBaseEntity<MeasuredValue>
        {

        public DateTime Timestamp { get; set; }

        .
        .
        .

        private double _value;
        [Range(0.0, double.MaxValue)]
        public double Value
        {
            get { return _value; }
            set
            {
                _value = value;
                RaisePropertyChanged("Value");
            }
        }

        private bool _isEditable;
        public bool IsEditable
        {
            get { return _isEditable; }
            set 
            {
                _isEditable = value;
                RaisePropertyChanged(() => IsEditable);
            }
        }

    }
}
4

0 回答 0