I have a WPF Application using MVVM pattern. I have a Window in my project and use a CustomControl in my Window.
I need two commands in my Window for Start and Stop in my CustomControl . So I use a bool DependencyProperty like this :
public static readonly DependencyProperty IsStartModeProperty = DependencyProperty.Register(
"IsStartMode", typeof(bool), typeof(RadarView), new FrameworkPropertyMetadata(false, OnCurrentReadingChanged));
public bool IsStartMode {
get { return (bool)GetValue(IsStartModeProperty); }
set { SetValue(IsStartModeProperty, value); }
}
Also following method is use for callback delegate in my dependency property:
public static void OnCurrentReadingChanged(DependencyObject doj, DependencyPropertyChangedEventArgs dp) {
if (IsStartMode)
Start();
else
Stop();
}
My problem is in use from IsStartMode property in up method, because this is not static. It has a build error.
Is Correct my solution? if is correct what I do?
You need to cast the first method argument to your Dependency Object class:
(As a side note, I would call the property
IsRunning.)