Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

TreeViewItems not displaying checkbox in heirarchicaldatatemplate

$
0
0

Hi,

I have a treeview with heirachical data for 4 levels.

The heirachicaldatatemplate is designed to display checkboxes.

Heirachicaldatatemplate's Itemsource is binded to "Models" which is an observable collection of class Model, implements TreeViewItem Class.

But on runtime, checkboxes are not displaying in the treeview.

Please help me out.

Here are the code:

publicclassModel : TreeViewItem

{

public Model()

{

}

publicstring Caption

{

get {return (string)GetValue(CaptionProperty); }

set { SetValue(CaptionProperty,value); }

}

publicstaticreadonly DependencyProperty CaptionProperty =

DependencyProperty.Register("Caption",typeof(string), typeof(Model), newPropertyMetadata(String.Empty));

publicObservableCollection<Model> Models

{

get {return (ObservableCollection<Model>)GetValue(ModelsProperty); }

set { SetValue(ModelsProperty,value); }

}

publicstaticreadonly DependencyProperty ModelsProperty =

DependencyProperty.Register("Models",typeof(ObservableCollection<Model>),typeof(Model),newPropertyMetadata(null));

}

publicpartialclass HCOmboBox : Window

{

publicObservableCollection<Model> Models

       {

           get { return (ObservableCollection<Model>)GetValue(ModelsProperty); }

           set { SetValue(ModelsProperty, value); }

       }

       

       publicstaticreadonlyDependencyProperty ModelsProperty =

           DependencyProperty.Register("Models",typeof(ObservableCollection<Model>),typeof(HCOmboBox),newPropertyMetadata(null));

}

<Style x:Uid="Style_6" TargetType="{x:Type TreeViewItem}" x:Key="2"

BasedOn="{StaticResource {x:Type TreeViewItem}}">

<Setter x:Uid="Setter_59" Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>

<Setter x:Uid="Setter_61" Property="IsSelected" Value="False"/>

<Setter x:Uid="Setter_62" Property="Height" Value="Auto"/>

</Style>

<HierarchicalDataTemplate x:Uid="HierarchicalDataTemplate_1" x:Key="1"

ItemsSource="{Binding Models}">

<CheckBox x:Uid="CheckBox_1" ClickMode="Press" IsChecked="{Binding

Path=IsChecked,Mode=TwoWay}"

Command="{Binding RelativeSource={RelativeSource FindAncestor,

AncestorType={x:Type local:HComboBox}}, Path=CheckAll,

Mode=TwoWay}"CommandParameter="{Binding}">

<TextBlock x:Uid="TextBlock_1" Text="{Binding Caption}"></TextBlock>

</CheckBox>

</HierarchicalDataTemplate>

<TreeView x:Uid="treeview" x:Name="treeview"

ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:HComboBox}}, Path=Models,Mode=TwoWay}"ItemContainerStyle="{StaticResource 2}" BorderThickness="0" Width="Auto" MinWidth="278" MinHeight="150"HorizontalAlignment="Left" VerticalAlignment="Top"ItemTemplate="{StaticResource 1}"TextSearch.TextPath="Caption"IsTextSearchEnabled="True"VirtualizingStackPanel.IsVirtualizing="True"VirtualizingStackPanel.VirtualizationMode="Recycling"/>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>