[英]WPF how to bidirectionally link a checkBox to a class member AND to another static variable
I have a checkbox which is binded to a class variable in the xaml code: 我有一个复选框绑定到xaml代码中的类变量:
<CheckBox x:Name="cbxUseBubbleNotifications" Margin="20" IsChecked="{Binding Path=pcdLoggerData.UseBubbleNotifications, Mode=TwoWay}" Content="_Use bubble notifications" HorizontalAlignment="Left" VerticalAlignment="Top" Style="{DynamicResource CheckboxSwitchStyle}" />
this should be supposed to be a two way binding but what happen is: 这应该是双向绑定,但是发生的是:
point 4 is not correct: since two way I expect to do that automatically. 第4点是不正确的:因为我希望通过两种方式自动执行此操作。
My class is: 我的课是:
[DataContract]
public class PCDLoggerBinSerializableData
{
public PCDLoggerBinSerializableData() { }
public PCDLoggerBinSerializableData(string _languageInUse, bool _useBubbleNotifications)
{
LanguageInUse = _languageInUse;
UseBubbleNotifications = _useBubbleNotifications;
}
[DataMember]
public string LanguageInUse { get; set; }
[DataMember]
public bool UseBubbleNotifications { get; set; }
}
}
Even more important I have to set another variable according to the same value/variations of pcdLogger.UseBubbleNotifications and that is a STATIC var. 更重要的是,我必须根据pcdLogger.UseBubbleNotifications的相同值/变量设置另一个变量,这是一个STATIC变量。 something like Bubble.NoBubbles = !pcdmisData.UseBubbleNotifications
像Bubble.NoBubbles =!pcdmisData.UseBubbleNotifications
So two problems: 有两个问题:
Thanks 谢谢
--ADD-- - 加 -
Not working I put breakpoints in all parts of the class and they never were it. 没有工作,我在全班同学中都设置了断点,但从来没有。
This is how I did it: 这是我的方法:
[DataContract]
public class PCDLoggerBinSerializableData: INotifyPropertyChanged
{
#region CONSTRUCTORS
public PCDLoggerBinSerializableData() { }
public PCDLoggerBinSerializableData(string _languageInUse, bool _useBubbleNotifications)
{
LanguageInUse = _languageInUse;
UseBubbleNotifications = _useBubbleNotifications;
}
#endregion
#region OPTIONS
[DataMember]
public string LanguageInUse { get; set; }
[DataMember]
private bool useBubbleNotifications;
public bool UseBubbleNotifications
{
get { return useBubbleNotifications; }
set
{
useBubbleNotifications = value;
Bubble.NoBubblesPlease = !useBubbleNotifications;
OnPropertyChange("UseBubbleNotifications");
}
}
#endregion
#region NOTIFIER
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChange(string inName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("inName"));
}
#endregion
}
It would be something like: 就像这样:
public bool UseBubbleNotifications
{
get
{
return useBubbleNotifications;
}
set
{
useBubbleNotifications = value;
Other_Static_Variable = value;
OnPropertyChange("UseBubbleNotifications");
}
}
public void OnPropertyChange(string inName)
{
if(PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("inName"));
}
}
Something like this may work. 这样的事情可能会起作用。 Of course your class would have to inherit the INotifyPropertyChanged interface.
当然,您的类将必须继承INotifyPropertyChanged接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.