什麼,我想實現的是,當被選中該複選框,文本框會顯示True,則該複選框取消選中,文本框將顯示假。綁定問題 - 價值不更新上查看
目前最大的問題是,最初它的工作原理,該複選框將被選中,並且文本框會顯示正確的。但是,當我取消選中它時,文本框仍然顯示爲True。
對不起,如果我失去了一些東西簡單,仍然試圖掌握WPF和C#。
感謝您的幫助。
的XAML:
<Grid>
<CheckBox Content="Check me" HorizontalAlignment="Left" Height="19" Margin="88,63,0,0" VerticalAlignment="Top" Width="86" IsChecked="{Binding CurrentValue, Mode= TwoWay}"/>
<TextBlock Text="{Binding CurrentValue, Mode=TwoWay}" HorizontalAlignment="Left" Height="39" Margin="88,82,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="86"/>
</Grid>
主窗口:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainView();
}
}
的MainView:
public class MainView : INotifyPropertyChanged
{
private bool currentValue = true;
public event PropertyChangedEventHandler PropertyChanged;
public bool CurrentValue
{
get
{
return currentValue;
}
set
{
if (currentValue == value)
{
return;
}
currentValue = value;
RaisePropertyChange("Check_Value");
}
}
protected void RaisePropertyChange(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
這解決了它。我確定我已經試過了。謝謝。 – user2469515