[英]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.