开发者

Disable property on Visual Studio Properties Panel

开发者 https://www.devze.com 2023-02-28 08:05 出处:网络
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

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" te开发者_开发技巧xt. 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>
0

精彩评论

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