[英]Copying text from ReadOnly cell in Xceed PropertyGrid
我具有綁定到PropertyGrid的ReadOnly屬性,並且希望用戶能夠從單元格中選擇和復制文本。 我需要使用其他屬性嗎? 如果是這樣,我應該使用哪個? 還是有其他解決方案?
謝謝,
請不要在屬性上使用[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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.