Reputation: 683
I have a custom WPF control that has a DependencyProperty:
public static readonly DependencyProperty DeferedVisibilityProperty;
private static void OnDeferedVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
var control = (CircularProgressBar)d;
control.OnDeferedVisibilityChanged();
}
public bool DeferedVisibility {
get => (bool)GetValue(DeferedVisibilityProperty);
set => SetValue(DeferedVisibilityProperty, value);
}
private void OnDeferedVisibilityChanged() {
if(DeferedVisibility) {
VisualStateManager.GoToState(this, "Visible", true);
Visibility = Visibility.Visible;
} else {
VisualStateManager.GoToState(this, "Collapsed", true);
Visibility = Visibility.Collapsed;
}
}
Now we can set visibility without bool-to-visibility converter. When using the Visibility DependencyProperty it does not work any more, so i want to mark it as obsolete.
I know you can mark members like this [Obsolete("Please use DeferedVisibility")]
.
So how can I mark the Visibility Property of the base class as obsolete?
Upvotes: 2
Views: 422
Reputation: 7325
Just do override the Visibility dependency property:
[Obsolete("Use something else")]
public new Visibility Visibility
{
get { return (Visibility)GetValue(VisibilityProperty); }
set { SetValue(VisibilityProperty, value); }
}
[Obsolete("Use something else")]
public new static readonly DependencyProperty VisibilityProperty =
DependencyProperty.Register(nameof(Visibility), typeof(Visibility), typeof(YourCustomControl), new PropertyMetadata(0));
But the problem I see, is that obsolete will only be marked in code behind, not in XAML(at least by me)
Upvotes: 2