开发者

dependent property does not change when changed via the view setter of a listview during design time

开发者 https://www.devze.com 2023-02-06 17:04 出处:网络
[Category(\"SomeCat\")] [Description(\"Gets or sets how items are displayed in the ShellListView control.\")]
[Category("SomeCat")]
[Description("Gets or sets how items are displayed in the ShellListView control.")]
[DefaultValue(View.Details)]
new public View View
{
    get { return base.View; }
    set
    {
        System.Diagnostics.Debug.WriteLine("View");

        if (value != View.LargeIcon)
        {
            //Reset these values because they can only be true if LargeIcon is set.
            ShowExtraLargeIcons = false;
        }

        base.View = value;
    }
}    

private bool m_ShowExtraLargeIcons;

[Category("Appearance")]
[DefaultValue(false)]
public bool ShowExtraLargeIcons
{
    get { return m_ShowExtraLargeIcons; }
    set
    {
        if (m_ShowExtraLargeIcons == value) 
            return;

        System.Diagnostics.Debug.WriteLine("Extra");

        m_ShowExtraLargeIcons = value;

        if (m_ShowExtraLargeIcons)
        // Always set view to LargeIcon if ShowExtraLargeIcons is enabled
            View = View.LargeIcon;
    }
}

My problem: If I set View to something else than LargeIcons (via the property manager of VS 2010), the ShowExtraLargeIcons-property remains True although it has been set to False.

If I set the ShowExtraLargeIcons to True, the property View is set to LargeIcons as expected.

Something that might help: The Debug-messages ("View" and "Extra") after setting ShowExtraLargeIcons are sho开发者_如何学Gown, after setting View they are not (both set during design time).


This has nothing to do with dependency properties, it's simply the behavior of the property browser.

When you use the new modifier on a class member, you are not creating an "override". ListView.View is not a virtual property. You are creating a completely new property (MyListView.View) which has the same signature and name.

The property browser is going to enumerate properties and use descriptors to work with them. It will see two completely different properties and either display both of them, or pick one arbitrarily.


new public View

Looks like you are editing some parant object if trace is not shown. And that paranet object is edited without influencing m_ShowExtraLargeIcons var.

0

精彩评论

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

关注公众号