DesignModeValueProvider.TranslatePropertyValue 方法 (PropertyIdentifier, Object)

更新:2007 年 11 月

捕获用户在设计器中进行的属性更改,并使用自定义逻辑在设计时提供新值。

命名空间:  Microsoft.Windows.Design.Model
程序集:  Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)

语法

声明
Public Overridable Function TranslatePropertyValue ( _
    identifier As PropertyIdentifier, _
    value As Object _
) As Object
用法
Dim instance As DesignModeValueProvider
Dim identifier As PropertyIdentifier
Dim value As Object
Dim returnValue As Object

returnValue = instance.TranslatePropertyValue(identifier, _
    value)
public virtual Object TranslatePropertyValue(
    PropertyIdentifier identifier,
    Object value
)
public:
virtual Object^ TranslatePropertyValue(
    PropertyIdentifier^ identifier, 
    Object^ value
)
public function TranslatePropertyValue(
    identifier : PropertyIdentifier, 
    value : Object
) : Object

参数

返回值

类型:System.Object

要在设计器中为属性设置的值。

异常

异常 条件
ArgumentNullException

identifier 为 nullnull 引用(在 Visual Basic 中为 Nothing)。

备注

针对 Properties 中的每个属性调用一次 TranslatePropertyValue。返回值可以是新值,也可以与传递给方法的值相同。

这些更改只影响设计器。在运行时,属性显示为用户设置的值。

重要说明:

使用此技术时,设计器中的属性行为与 XAML 视图中的属性值不匹配。XAML 视图显示用户在设计时输入的值。XAML 视图中的值表示该属性将在运行时展现的行为。

示例

下面的示例重写 TranslatePropertyValue 方法。您更改 ButtonContent 属性,使它在设计器中显示为大写。您还可以更改 ButtonBackground 属性,以使它在设计器中显示为默认系统颜色。这些更改只影响设计器。在运行时,ContentBackground 属性显示为用户设置的值。此代码示例摘自为 DesignModeValueProvider 类提供的一个更大的示例。

有关更多信息,请参见演练:在设计时更改属性的行为

Public Overrides Function TranslatePropertyValue(ByVal identifier As PropertyIdentifier, ByVal value As Object) As Object

    If identifier.DependencyProperty Is Button.ContentProperty Then

        Return value.ToString().ToUpper()
    End If

    If identifier.DependencyProperty Is Button.BackgroundProperty Then

        Return New SolidColorBrush(SystemColors.ControlColor)
    End If

    Return MyBase.TranslatePropertyValue(identifier, value)
End Function
public override object TranslatePropertyValue(PropertyIdentifier identifier, object value)
{
    if (identifier.DependencyProperty == Button.ContentProperty)
    {
        return ((string)value).ToUpper();
    }

    if (identifier.DependencyProperty == Button.BackgroundProperty)
    {
        return new SolidColorBrush(SystemColors.ControlColor);
    }

    return base.TranslatePropertyValue(identifier, value);
}

权限

另请参见

参考

DesignModeValueProvider 类

DesignModeValueProvider 成员

TranslatePropertyValue 重载

Microsoft.Windows.Design.Model 命名空间

其他资源

如何:在设计时更改属性的行为

WPF 设计器扩展性体系结构

属性编辑体系结构

功能提供程序和功能连接器