[英]WPF how to bidirectionally link a checkBox to a class member AND to another static variable
我有一个复选框绑定到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}" />
这应该是双向绑定,但是发生的是:
第4点是不正确的:因为我希望通过两种方式自动执行此操作。
我的课是:
[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; }
}
}
更重要的是,我必须根据pcdLogger.UseBubbleNotifications的相同值/变量设置另一个变量,这是一个STATIC变量。 像Bubble.NoBubbles =!pcdmisData.UseBubbleNotifications
有两个问题:
谢谢
- 加 -
没有工作,我在全班同学中都设置了断点,但从来没有。
这是我的方法:
[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
}
就像这样:
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"));
}
}
这样的事情可能会起作用。 当然,您的类将必须继承INotifyPropertyChanged接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.