共用方式為


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 方法,該方法讓現有或系統對話方塊得以重複使用。

下列清單顯示的規則用於判斷是否已使用 DataTemplateShowDialog 方法。

  • 如果 DialogEditorTemplate 屬性不是 nullNull 參照 (即 Visual Basic 中的 Nothing),該 DataTemplate 會裝載於可提供裝載樣式的主應用程式特定對話方塊中。不會呼叫 ShowDialog

  • 如果 DialogEditorTemplate 屬性為 nullNull 參照 (即 Visual Basic 中的 Nothing),則會呼叫虛擬 ShowDialog 方法,且您可以覆寫這個方法以顯示任何對話方塊。

範例

下列程式碼範例示範如何建立對話方塊屬性值編輯器,這會在 [屬性] 視窗中按一下自訂 [FileName] 屬性時,顯示開啟檔案對話方塊。如需詳細資訊,請參閱 HOW TO:建立對話方塊屬性值編輯器

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

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

DialogPropertyValueEditor 成員

Microsoft.Windows.Design.PropertyEditing 命名空間

EditModeSwitchButton

PropertyEntry

PropertyValue

PropertyValueEditorCommands

IInputElement

其他資源

屬性編輯架構

WPF 設計工具擴充性