Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Treeview - Get status of checkbox
    primarykey
    data
    text
    <p>I have created a Treeview and used a stack panel to include a checkbox, icon image and text for each node in the tree. These nodes are created at runtime. I also have a button object. The xaml is below.</p> <p>The problem i have is that, when the click me button is clicked, i need to traverse thru the tree view and if a checkbox is checked, perform some function.</p> <p><strong>Does anyone know how to find out if the checkbox for a node in the tree is checked, from the C# code behind ???</strong></p> <pre><code>&lt;Window x:Class="WPF_Explorer_Tree.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WPF_Explorer_Tree" Title="KryptoG" Height="424" Width="815" Loaded="Window_Loaded"&gt; &lt;Window.Resources&gt; &lt;local:HeaderConverter x:Key="formatter" /&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;TreeView x:Name="foldersItem" SelectedItemChanged="foldersItem_SelectedItemChanged" Background="#FFFFFFFF" BorderBrush="#FFFFFFFF" Foreground="#FFFFFFFF" Margin="0,0,236,112" AllowDrop="True" Visibility="Visible"&gt; &lt;TreeView.Resources&gt; &lt;Style TargetType="{x:Type TreeViewItem}"&gt; &lt;Setter Property="HeaderTemplate"&gt; &lt;Setter.Value&gt; &lt;DataTemplate&gt; &lt;StackPanel Name="ST" Orientation="Horizontal"&gt; &lt;CheckBox VerticalAlignment="Center" Name="SelectedCheckBox" IsChecked="False" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" /&gt; &lt;Image Name="img" Width="20" Stretch="Fill" Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}, Path=Header, Converter={x:Static local:HeaderToImageConverter.InstanceIcon}}" /&gt; &lt;TextBlock VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}, Path=Header, Converter={StaticResource formatter}}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/TreeView.Resources&gt; &lt;/TreeView&gt; &lt;TreeView HorizontalAlignment="Right" Margin="0,0,12,12" Name="treeView1" Width="204" AllowDrop="True" BorderBrush="White" Foreground="White" /&gt; &lt;Button Height="23" HorizontalAlignment="Left" Margin="12,0,0,70" Name="button1" VerticalAlignment="Bottom" Width="75" Click="button1_Click"&gt;Click Me&lt;/Button&gt; &lt;Button Height="23" HorizontalAlignment="Left" Margin="267,0,0,69" Name="button2" VerticalAlignment="Bottom" Width="75" Click="button2_Click"&gt;Click Me too&lt;/Button&gt; &lt;/Grid&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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