DialogPropertyValueEditor 类
更新:2007 年 11 月
PropertyEntry 对象的所有对话框编辑逻辑的容器。
命名空间: Microsoft.Windows.Design.PropertyEditing
程序集: Microsoft.Windows.Design(在 Microsoft.Windows.Design.dll 中)
语法
声明
Public Class DialogPropertyValueEditor _
Inherits PropertyValueEditor
用法
Dim instance As DialogPropertyValueEditor
public class DialogPropertyValueEditor : PropertyValueEditor
public ref class DialogPropertyValueEditor : public PropertyValueEditor
public class DialogPropertyValueEditor extends PropertyValueEditor
备注
使用 DialogPropertyValueEditor 类可显示一个具有关联对话框编辑器的内联编辑器。
DialogPropertyValueEditor 类可以包含一个用于对话框编辑器的 DataTemplate,或包含在调用对话框时要调用的自定义逻辑。
使用 DataTemplate 中的 EditModeSwitchButton 来调用自定义 DialogPropertyValueEditor 类。
可以提供在宿主对话框中显示的 DataTemplate,也可重写 ShowDialog 方法,这允许重用现有对话框或系统对话框。
下面的列表显示用来确定是使用 DataTemplate 还是 ShowDialog 方法的规则。
如果 DialogEditorTemplate 属性不为 nullnull 引用(在 Visual Basic 中为 Nothing),则该 DataTemplate 承载在特定于宿主的对话框中,该对话框提供宿主样式。不调用 ShowDialog。
如果 DialogEditorTemplate 属性为 nullnull 引用(在 Visual Basic 中为 Nothing),则调用 ShowDialog 虚方法并且您可以重写此方法来显示任何对话框。
示例
下面的代码示例演示如何创建一个对话框属性值编辑器,当在“属性”窗口中单击自定义的“文件名”属性时,该编辑器将显示一个“打开文件”对话框。有关更多信息,请参见如何:创建对话框属性值编辑器。
using System;
using System.ComponentModel;
using System.Windows;
using Microsoft.Windows.Design.Metadata;
using Microsoft.Windows.Design.PropertyEditing;
using Microsoft.Win32;
namespace CustomControlLibrary.Design
{
public class FileBrowserDialogPropertyValueEditor : DialogPropertyValueEditor
{
private EditorResources res = new EditorResources();
public FileBrowserDialogPropertyValueEditor()
{
this.InlineEditorTemplate = res["FileBrowserInlineEditorTemplate"] as DataTemplate;
}
public override void ShowDialog(
PropertyValue propertyValue,
IInputElement commandSource)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false;
if (ofd.ShowDialog() == true)
{
propertyValue.StringValue = ofd.FileName;
}
}
}
}
<ResourceDictionary xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:PropertyEditing="clr-namespace:Microsoft.Windows.Design.PropertyEditing;assembly=Microsoft.Windows.Design"
xmlns:Local="clr-namespace:CustomControlLibrary.Design"
x:Class="CustomControlLibrary.Design.EditorResources">
<DataTemplate x:Key="FileBrowserInlineEditorTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding StringValue}"/>
<PropertyEditing:EditModeSwitchButton Grid.Column="1"/>
</Grid>
</DataTemplate>
</ResourceDictionary>
继承层次结构
System.Object
Microsoft.Windows.Design.PropertyEditing.PropertyValueEditor
Microsoft.Windows.Design.PropertyEditing.DialogPropertyValueEditor
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
另请参见
参考
Microsoft.Windows.Design.PropertyEditing 命名空间