Share via


DesignModeValueProvider Class

Captures property changes that are made by the user in the designer and provides new values at design time.

Namespace:  Microsoft.Windows.Design.Model
Assembly:  Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)

Syntax

'Declaration
Public Class DesignModeValueProvider _
    Inherits FeatureProvider
'Usage
Dim instance As DesignModeValueProvider
public class DesignModeValueProvider : FeatureProvider
public ref class DesignModeValueProvider : public FeatureProvider
public class DesignModeValueProvider extends FeatureProvider

Remarks

Normally, when a user changes a property value of an object in the designer, that value is set on the object in the designer. By using the DesignModeValueProvider class, you can insert your own logic into this process. For example, you want the user to be able to set the visible property of a control to false, but the control should still be visible at design time.

To accomplish this, you create a DesignModeValueProvider and attach it to your custom control. The DesignModeValueProvider captures property changes that the user makes, you insert your own logic in the TranslatePropertyValue method, and the DesignModeValueProvider passes the new values to the designer.

Important noteImportant Note:

When you use this technique, the behavior of a property in the designer does not match the value of the property in XAML view. XAML view displays the value that the user entered at design time. The value in XAML view represents the behavior that the property will exhibit at run time.

Examples

The following example creates a custom DesignModeValueProvider that will be attached to a custom button control. In the TranslatePropertyValue method, you change the Content property of the Button so that it appears uppercase in the designer. You also change the Background property of the Button so that it appears with the default system color in the designer. These changes affect the designer only. At run time, the Content and the Background properties appear with the values set by the user.

For more information, see Walkthrough: Changing the Behavior of a Property at Design Time.

Imports System
Imports System.Windows                  'SystemColors
Imports System.Windows.Media            'SolidColorBrush
Imports System.Windows.Controls         'Button
Imports Microsoft.Windows.Design.Model  'DesignModeValueProvider

Namespace CustomButton

    Public Class CustomButtonDesignModeValueProvider
        Inherits DesignModeValueProvider


        Public Sub New()

            Properties.Add(Button.ContentProperty)
            Properties.Add(Button.BackgroundProperty)
        End Sub 



        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 
    End Class 
End Namespace
using System;
using System.Windows;                   //SystemColors 
using System.Windows.Media;             //SolidColorBrush 
using System.Windows.Controls;          //Button 
using Microsoft.Windows.Design.Model;   //DesignModeValueProvider 
namespace CustomButton
{
    class CustomButtonDesignModeValueProvider : DesignModeValueProvider
    {

        public CustomButtonDesignModeValueProvider()
        {
            Properties.Add(Button.ContentProperty);
            Properties.Add(Button.BackgroundProperty);
        }


        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);
        }
    }
}

Inheritance Hierarchy

System.Object
  Microsoft.Windows.Design.Features.FeatureProvider
    Microsoft.Windows.Design.Model.DesignModeValueProvider

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

DesignModeValueProvider Members

Microsoft.Windows.Design.Model Namespace

Other Resources

How to: Change the Behavior of a Property at Design Time

WPF Designer Extensibility Architecture

Property Editing Architecture

Feature Providers and Feature Connectors