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" 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>
精彩评论