我試圖創建一個情況,其中一個或兩個ToggleButton
s可以在任何時間組。我遇到的問題是如果我更改UI狀態不更新的支持變量的狀態。WPF ToggleButton IsChecked綁定問題
我確實有INotifyPropertyChanged
實施。
我已經建立了我ToggleButton
就像這樣:
<ToggleButton IsChecked="{Binding Path=IsPermanentFailureState, Mode=TwoWay}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<TextBlock TextWrapping="Wrap"
TextAlignment="Center">Permanent Failure</TextBlock>
</ToggleButton>
<ToggleButton IsChecked="{Binding Path=IsTransitoryFailureState, Mode=TwoWay}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<TextBlock TextWrapping="Wrap"
TextAlignment="Center">Temporary Failure</TextBlock>
</ToggleButton>
這是我的後盾屬性(我使用的MVVM模式,其他的綁定工作,在ToggleButton
IE點擊確實進入這些屬性設置。當我改變通過代碼的狀態下,切換按鈕不改變視覺狀態,IE我設置爲後盾屬性設置爲false,但按鈕撐檢查。
public bool? IsPermanentFailureState
{
get { return isPermFailure; }
set
{
if (isPermFailure != value.Value)
{
NotifyPropertyChanged("IsPermanentFailureState");
}
isPermFailure = value.Value;
if (isPermFailure) IsTransitoryFailureState = false;
}
}
public bool? IsTransitoryFailureState
{
get { return isTransitoryFailureState; }
set
{
if (isTransitoryFailureState != value.Value)
{
NotifyPropertyChanged("IsTransitoryFailureState");
}
isTransitoryFailureState = value.Value;
if (isTransitoryFailureState) IsPermanentFailureState = false;
}
}
你打敗了我肯特。從我身上向上一箭。 – 2009-09-04 12:32:55
哇 - 我不應該是這個笨蛋!這可能是你坐下來編碼的時候發生的事情。謝謝! – 2009-09-04 13:08:31