我将ReadOnly属性绑定到PropertyGrid,我希望用户能够从单元格中选择和复制文本。 我需要使用不同的属性吗?如果是这样我应该使用哪个? 或者可能有不同的解决方案?
谢谢,
答案 0 :(得分:0)
请不要在酒店使用[ReadOnly(true)]。 但是,可以通过将其设置为ReadOnly TextBox来限制在xceed属性网格中右侧编辑属性值,如下所示:
的.xaml:
<xctk:PropertyGrid x:Name="MyPrpGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
FontWeight="ExtraBold" ShowSearchBox="False" ShowSortOptions="False"
SelectedObject="{Binding BindedPropName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Background="#FF4A5D80" Foreground="White" >
<xctk:PropertyGrid.EditorDefinitions>
<!-- For Id, Text and Type fields at left-side in the xceed property grid, replace right-side value area with ReadOnly TextBox -->
<xctk:EditorDefinition>
<xctk:EditorDefinition.PropertiesDefinitions>
<xctk:PropertyDefinition Name="Id"/> <!-- BindedPropName.Id -->
<xctk:PropertyDefinition Name="Text" /> <!-- BindedPropName.Text -->
<xctk:PropertyDefinition Name="Type" /> <!-- BindedPropName.Type -->
</xctk:EditorDefinition.PropertiesDefinitions>
<xctk:EditorDefinition.EditorTemplate>
<DataTemplate>
<!-- Binded Value is a DependencyProperty which is defined in view model -->
<TextBox IsReadOnly="True" Text="{Binding Value}" BorderThickness="0"/>
</DataTemplate>
</xctk:EditorDefinition.EditorTemplate>
</xctk:EditorDefinition>
</xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>
MyViewModel.cs应该来自DependencyObject。
MyViewModel.cs:
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(MyViewModel),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public string Value
{
get { return (string)GetValue(ValueProperty); } // GetValue() is from derived DependencyObject class
set { SetValue(ValueProperty, value); } // SetValue() is from derived DependencyObject class
}