简体   繁体   中英

Disable property on Visual Studio Properties Panel

I'm new with wpf. I am currently developing custom control, and I want certain properties to be defined strictly from xaml. Example for what I'm trying to achieve is the Effect property, which only shows "Value must be set in XAML" text. Could someone tell me how to do that, or which attribute should I use? Thanks in advance

If you want to hide properties from Properties Panel you can achieve it with BrowsableAttribute:

BrowsableAttribute Class

A visual designer typically displays in the Properties window those members that either have no browsable attribute or are marked with the BrowsableAttribute constructor of the value true. These members can be modified at design time. Members marked with the BrowsableAttribute constructor of the value false are not appropriate for design-time editing and therefore are not displayed in a visual designer . The default is true.

[Browsable(false)]
public int HiddenProperty {
    get {
        // Insert code here.
        return 0;
    }
    set {
        // Insert code here.
    }
}

You need dependancy properties

http://msdn.microsoft.com/en-us/library/ms752914.aspx

    public static readonly DependencyProperty IsSpinningProperty = 
    DependencyProperty.Register(
    "IsSpinning", typeof(Boolean),...);

public bool IsSpinning
{
    get { return (bool)GetValue(IsSpinningProperty); }
    set { SetValue(IsSpinningProperty, value); }
}

Or simply add the effect to the xaml of yuor new control:

<local:NewControl>
    <local:NewControl.Effect>
        <DropShadowEffect/>
    </local:NewControl.Effect>
</local:NewControl>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM