开发者

WPF Designer - User defined Settings

Is it possible to define some settings for the wpf designer? I'd like to offer the user 2 display modes: "Draw Everything with开发者_运维技巧 Borders" and "Runtime View". My Custom Components should then be able to check the settings and draw themselfes accordingly.


I have a suggestion, why don't you just add a DependencyProperty your Custom Component that will be "DisplayMode" and depending of that the developer put in the property (from Xaml or C#) that the Custom Component will render the way you want?

    public static readonly DependencyProperty DisplayModeProperty = DependencyProperty.Register(
          "DisplayMode", typeof(int), typeof(DisplayModeProperty), new PropertyMetadata(1, OnModeChanged));

    public bool DisplayMode
    {
        private get { return (bool)GetValue(DisplayModeProperty); }
        set { SetValue(DisplayModeProperty, value); }
    }
    private static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ((MyCustomComponent)d).OnModeChanged(e);
    }
    private void OnModeChanged(DependencyPropertyChangedEventArgs e)
    {
        int mode = Convert.ToInt32(e.NewValue);
        if(mode == 1)
        {
        //... Render for the Mode 1
        }
        else
        {
        //... Render for the Mode 2
        }

    }

In the Xaml :

 <cust:MyCustomCompoenent DisplayMode="1"/>


I think Strategy Pattern can help you here. Define one abstract base class with common preferences, and define multiple concrete classes deriving from it. Each concrete class will define some policies (can override some as well), such as border or no border, colors, themes, and so on, which you can use in your view. You can change the preferences at runtime if you access the preferences using the base class reference whose runtime type will be one of the concrete class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜