设置DataTemplate的DataGridViewColumn的IsReadOnlyProperty

时间:2017-04-13 14:42:47

标签: wpf xaml telerik-grid

如果使用DataTemplate,如何将整列设置为ReadOnly? 我想要的是关闭整个组合框列的选择,它不应该是可编辑和可选择的。原因是我想在ViewModel中设置属性时关闭某些列的选择。

我还可以将组合框的IsEnabled属性设置为多重绑定转换器以实现此目标。但有更简单的方法吗?

我有以下XAML:

IsReadOnly属性设置为True,但带有组合框的整个列保持可选。

                  <ffm:CustRadGridViewDataColumn
                        Name="_colVariableType"
                        IsReadOnly="True"
                        Width="120"
                        ApplicationModelField="VariableType"
                        DataType="{Binding ColumnVariableDataType, Mode=TwoWay}"
                        Header="Variable Type"                                  
                        UniqueName="VariableType">

                        <ffm:CustRadGridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox
                                    IsEditable="False"
                                    SelectedItem="{Binding Path=VariableType, Mode=TwoWay}"
                                    ItemsSource="{Binding Path=VariableTypeOptions}"
                                    IsEnabled="{Binding Path=IsLocked, 
                                                        Mode=TwoWay, 
                                                        UpdateSourceTrigger=PropertyChanged, 
                                                        Converter={StaticResource InverseBooleanConverter}}"
                                    IsManipulationEnabled="{Binding Path=IsLocked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanConverter}}" 
                                    />
                            </DataTemplate>
                        </ffm:CustRadGridViewDataColumn.CellTemplate>

                        <ffm:CustRadGridViewDataColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox
                                    IsEditable="False"
                                    SelectedItem="{Binding Path=VariableType, Mode=TwoWay}"
                                    ItemsSource="{Binding Path=VariableTypeOptions}"
                                    IsEnabled="{Binding Path=IsLocked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanConverter}}"
                                    IsManipulationEnabled="{Binding Path=IsLocked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanConverter}}" />
                            </DataTemplate>
                        </ffm:CustRadGridViewDataColumn.CellEditTemplate>
                    </ffm:CustRadGridViewDataColumn>

如果我在其中使用与TextBox相同的代码,一切正常:

              <ffm:CustRadGridView.Columns>
                    <ffm:CustRadGridViewDataColumn
                        Name="_colName"
                        Width="200"
                        ApplicationModelField="Name"
                        Header="Name"
                        IsReadOnly="True"
                        UniqueName="Name">

                        <ffm:CustRadGridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock
                                    IsEnabled="{Binding IsLocked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanConverter}}"
                                    IsManipulationEnabled="{Binding Path=IsLocked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanConverter}}"
                                    Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </ffm:CustRadGridViewDataColumn.CellTemplate>

                        <ffm:CustRadGridViewDataColumn.CellEditTemplate>
                            <DataTemplate>
                                <TextBox
                                    IsEnabled="{Binding Path=IsLocked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanConverter}}"
                                    IsManipulationEnabled="{Binding Path=IsLocked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanConverter}}"
                                    Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </ffm:CustRadGridViewDataColumn.CellEditTemplate>

                    </ffm:CustRadGridViewDataColumn>

0 个答案:

没有答案