DialogPropertyValueEditor 類別

PropertyEntry 物件之所有對話方塊編輯邏輯的容器。

繼承階層架構

System.Object
  Microsoft.Windows.Design.PropertyEditing.PropertyValueEditor
    Microsoft.Windows.Design.PropertyEditing.DialogPropertyValueEditor

命名空間:  Microsoft.Windows.Design.PropertyEditing
組件:  Microsoft.Windows.Design.Interaction (在 Microsoft.Windows.Design.Interaction.dll 中)

語法

'宣告
Public Class DialogPropertyValueEditor _
    Inherits PropertyValueEditor
public class DialogPropertyValueEditor : PropertyValueEditor
public ref class DialogPropertyValueEditor : public PropertyValueEditor
type DialogPropertyValueEditor =  
    class
        inherit PropertyValueEditor
    end
public class DialogPropertyValueEditor extends PropertyValueEditor

DialogPropertyValueEditor 型別會公開下列成員。

建構函式

  名稱 說明
公用方法 DialogPropertyValueEditor() 初始化 DialogPropertyValueEditor 類別的新執行個體。
公用方法 DialogPropertyValueEditor(DataTemplate, DataTemplate) 初始化 DialogPropertyValueEditor 類別的新執行個體。

回頁首

屬性

  名稱 說明
公用屬性 DialogEditorTemplate 取得或設定 DataTemplate,這會由主應用程式特定對話方塊裝載,並將 DataContext 設定為 PropertyValue
公用屬性 InlineEditorTemplate 取得或設定用於內嵌編輯器的 DataTemplate。 (繼承自 PropertyValueEditor)。

回頁首

方法

  名稱 說明
公用方法 Equals 判斷指定的 Object 和目前的 Object 是否相等。 (繼承自 Object)。
受保護的方法 Finalize 允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。 (繼承自 Object)。
公用方法 GetHashCode 做為特定型別的雜湊函式。 (繼承自 Object)。
公用方法 GetType 取得目前執行個體的 Type。 (繼承自 Object)。
受保護的方法 MemberwiseClone 建立目前 Object 的淺層複本 (Shallow Copy)。 (繼承自 Object)。
公用方法 ShowDialog DialogEditorTemplate 為 nullNull 參照 (即 Visual Basic 中的 Nothing) 而且使用者已叫用對話方塊時呼叫。
公用方法 ToString 傳回表示目前物件的字串。 (繼承自 Object)。

回頁首

備註

請使用 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.Interaction"
                    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>

執行緒安全

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

請參閱

參考

Microsoft.Windows.Design.PropertyEditing 命名空間

EditModeSwitchButton

PropertyEntry

PropertyValue

PropertyValueEditorCommands

IInputElement

其他資源

屬性編輯架構

WPF 設計工具擴充性