基于复选框的列上的WPF GridView SetReadOnly或Enabled



我有一个RadGridView(telerik版本的GridView),在这个RadGridView中我有以下列:

<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding Revoked}" AutoSelectOnEdit="True" Header="Revoked" UniqueName="Revoked" Width="Auto" IsReadOnly="False" FooterTextAlignment="Right" CellStyle="{StaticResource GridCellStyle}" />

我想基于复选框列在网格中的另外两列上启用/禁用或设置只读标志。

<telerik:GridViewDataColumn 
    DataMemberBinding="{Binding RevokedBy}" 
    Header="Revoked By" 
    UniqueName="RevokedBy" 
    Width="Auto" 
    IsReadOnly="{Binding Revoked}" 
    FooterTextAlignment="Right" 
    CellStyle="{StaticResource GridCellStyle}" />
<telerik:GridViewDataColumn 
    DataMemberBinding="{Binding RevokedDateTime}" 
    DataFormatString="dd/MM/yyyy HH:mm:ss" 
    Header="Revoked Date Time" 
    UniqueName="RevokedDateTime" 
    Width="Auto" 
    IsReadOnly="{Binding Revoked}" 
    FooterTextAlignment="Right" 
    CellStyle="{StaticResource GridCellStyle}">
   <telerik:GridViewDataColumn.CellEditTemplate>
       <DataTemplate>
           <WrapPanel Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="4">
               <telerik:RadDateTimePicker 
                   Margin="0 5 5 5" 
                   Width="250"
                   DisplayFormat="Short"                                     
                   InputMode="DatePicker" 
                   DateSelectionMode="Day"
                   DateTimeWatermarkContent="Select Date"
                   MaxWidth="155"
                   MinWidth="155"
                   SelectedDate="{Binding RevokedDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
               <telerik:RadMaskedDateTimeInput 
                   Margin="5"
                   Culture="en-GB"
                   EmptyContent="Enter Time"
                   InputBehavior="Replace"
                   Mask="HH:mm:ss"
                   SelectionOnFocus="SelectAll"
                   TextMode="MaskedText"
                   Value="{Binding RevokedTime, Mode=TwoWay}"/>
           </WrapPanel>
       </DataTemplate>
   </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

到目前为止,我已经尝试将IsReadOnlyIsEnabled属性绑定到Revoked,但这似乎不起作用,我可以看到Revoked属性正在设置中,RaisePropertyChanged事件正在重复。

任何帮助都将不胜感激。

更新:

视图模型:

/// <summary>
/// The agreements.
/// </summary>
private ObservableCollection<NotificationAgreement> agreements;
/// <summary>
/// Gets or sets the agreements.
/// </summary>
public ObservableCollection<NotificationAgreement> Agreements
{
    get
    {
        return this.agreements ?? (this.agreements = new ObservableCollection<NotificationAgreement>());
    }
    set
    {
        this.agreements = value;
        this.RaisePropertyChanged(() => this.Agreements);
    }
}

NotificationAgreement类具有以下属性。

/// <summary>
/// Gets or sets a value indicating whether revoked.
/// </summary>
public bool Revoked
{
    get
    {
        return this.revoked;
    }
    set
    {
        this.revoked = value;
        this.RaisePropertyChanged(() => this.Revoked);
    }
}

你能粘贴你的ViewModel吗?我只想知道当Revoked被更改时,你会发出通知来查看。

(1) 您的视图模型应该有一个ObservableCollection<yourObject>

(2) yourObject应实施INotifyPropertyChanged

(3) 您的对象应该具有以下方式的属性

private bool _revoked;
public bool Revoked 
{
   get{return _revoked;}
   set { _revoked=value;
         RaisPropertyChanged("Revoked");
}

这只是模拟代码,请按照您的方式执行。

最新更新