I have ReadOnly properties binded to PropertyGrid and I want users to be able to select and copy text from cells. Do I need to use a different attribute? If so which should I use? or maybe there is a different solution ?
Thanks,
I have ReadOnly properties binded to PropertyGrid and I want users to be able to select and copy text from cells. Do I need to use a different attribute? If so which should I use? or maybe there is a different solution ?
Thanks,
Please do not use [ReadOnly(true)] on the property. But editing property's value at right-side in the xceed property grid can be restricted by making it as ReadOnly TextBox as follows:
.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 should be derived from 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
}