Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would create a Two-Way data binding with that Check Box's IsChecked property to a ViewModel object instead. Much easier than navigating the tree. </p> <hr> <p><strong>Edit</strong> (per request of person asking):</p> <p>Here's an example View Model (very simple that is only accounting for the IsChecked property):</p> <pre><code>public class ViewModel : System.ComponentModel.INotifyPropertyChanged { private bool? _isChecekd; public bool? IsChecked { get { return _isChecekd; } set { if (_isChecekd != value) { _isChecekd = value; if (PropertyChanged != null) { PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("IsChecked")); } } } } #region INotifyPropertyChanged Members public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; #endregion } </code></pre> <p>Now that you have an object implementing INotifyPropertyChanged, you can bind UI element properties to them. So you would update the IsChecked property of your CheckBox to this property. To do that, you first have to set the DataContext of Window1 in some way (or you could just do this on the TreeView itself as well). In your Window1.xaml.cs:</p> <pre><code>public Window1() { InitializeComponent(); this.DataContext = new ViewModel(); } </code></pre> <p>Then, in your Window1.xaml file, update the CheckBox IsChecked property: </p> <pre><code>&lt;CheckBox VerticalAlignment="Center" Name="SelectedCheckBox" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" /&gt; </code></pre> <p>And then, in whatever code you need to be able to interrogate the currently value of IsChecked, you can get to it this way (assuming <strong>this</strong> is Window1):</p> <pre><code>((ViewModel)this.DataContext).IsChecked </code></pre> <p>Hope that helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload