Всем привет.
Попробовал у окна сделать статполе и к нему забиндиться. И что то не получается.
public partial class MainWindow : Window, INotifyPropertyChanged
{
#region PropertyChanges
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private static System.ComponentModel.PropertyChangedEventHandler StaticPropertyChanged;
static protected void OnStaticPropertyChanged([CallerMemberName] String propertyName = "")
{
System.ComponentModel.PropertyChangedEventArgs e = new System.ComponentModel.PropertyChangedEventArgs(propertyName);
System.ComponentModel.PropertyChangedEventHandler h = StaticPropertyChanged;
if (h != null)
h(null, e);
}
void StaticNotifyPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
// map the static name to the instance name
NotifyPropertyChanged(e.PropertyName);
}
#endregion
private static double _progress = 0.0;
public static double Progress
{
get
{
return _progress;
}
set
{
_progress = value;
OnStaticPropertyChanged();
}
}
}
XAML
/// Вариант 1 тут стаковерфлоу в конструкторе
<Window.Resources>
<ObjectDataProvider x:Key="ProgressManager" ObjectType="{x:Type local:MainWindow}" MethodName="Progress"/>
</Window.Resources>
<SomeElement
Value="{Binding Source={StaticResource ProgressManager}}" />
/// Вариант 2 так не биндится
<SomeElement
Value="{Binding Mode=OneWay, Source={x:Static local:MainWindow.Progress}}"/>
Проблему решил не статичным депенданси полем. Но вопрос вообще возможно реализовать привязку к статичному полю именно класса основного окна?
There are 10 types of people in the world: Those who understand binary, and those who don't.