如何修改用作RadPropertyGrid编辑器的RadFilePathPicker属性?
修改RadPropertyGrid中RadFilePathPicker编辑器的ReadOnly属性
方法1:通过EditorAttribute传递属性参数
Telerik的EditorAttribute支持在第三个参数中传入控件的属性键值对,直接指定ReadOnly属性的值:
[Telerik.Windows.Controls.Data.PropertyGrid.Editor( typeof(RadFilePathPicker), "FilePath", new Dictionary<string, object> { { "ReadOnly", false } })] public string HtmlSourceFile { get; set; }
方法2:自定义XAML编辑器模板
在窗口的Resources中定义自定义的编辑器模板,手动设置RadFilePathPicker的ReadOnly为false,然后在EditorAttribute中指定使用这个模板:
<Window.Resources> <DataTemplate x:Key="CustomFilePathPickerTemplate"> <telerik:RadFilePathPicker FilePath="{Binding Value, Mode=TwoWay}" ReadOnly="False"/> </DataTemplate> </Window.Resources>
代码中指定模板:
[Telerik.Windows.Controls.Data.PropertyGrid.Editor(typeof(DataTemplate), "", "CustomFilePathPickerTemplate")] public string HtmlSourceFile { get; set; }
方法3:利用AutoGeneratingPropertyItem事件修改控件属性
在RadPropertyGrid的AutoGeneratingPropertyItem事件中,定位到对应属性的编辑器控件,直接修改其ReadOnly属性:
private void RadPropertyGrid_AutoGeneratingPropertyItem(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyItemEventArgs e) { if (e.PropertyName == nameof(HtmlSourceFile)) { var filePathPicker = e.Editor as RadFilePathPicker; if (filePathPicker != null) { filePathPicker.ReadOnly = false; } } }
XAML中绑定事件:
<telerik:RadPropertyGrid AutoGeneratingPropertyItem="RadPropertyGrid_AutoGeneratingPropertyItem"/>
内容的提问来源于stack exchange,提问作者Damien
相关产品推荐
相关产品推荐

