Reputation: 125
In my application I want to prevent other programmers to set properties to my Usercontrols that maybe cause some troubles.
A simple example is that I don't want to allow that someone set UseLayoutRounding
to true.
<Button UseLayoutRounding="True"/>
I want to disable that Intelisense
shows me UseLayoutRounding
.
Upvotes: 1
Views: 234
Reputation: 1689
You may override OnPropertyChanged
method and throw exceptions when someone tries to change it:
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
if (e.Property == UseLayoutRoundingProperty && (bool)e.NewValue)
{
throw new PropertyIsImmutableException("UseLayoutRounding");
}
//....
base.OnPropertyChanged(e);
}
Or you may use new
keyword:
public new bool UseLayoutRounding
{
get { return (bool)GetValue(UseLayoutRoundingProperty); }
}
However, using second aproach without first remains posibility to change value like this:
yourSuperControl.SetValue(SuperControlType.UseLayoutRoundingProperty, true);
Upvotes: 1