wpf treeview HierarchicalDataTemplate get child control

i m using this article http://blogs.msdn.com/delay/archive/2009/09/23/if-it-walks-like-a-duck-and-talks-like-a-duck-it-must-be-a-treegrid-a-simple-xaml-only-treegrid-ui-for-wpf.aspx

to have hierarchical data... i am having treeview which contains grid and that grid contains textboxes...

i just want to hide/show some columns at runtime of the grid in treeview... at any level.. no matter at parent/child...


One way to do this is to use the ViewModel concept. A ViewModel is a data structure that represents the UI view of the app, it is the model (the data) + information typically needed for the UI.

In your example, you could have a new class that wraps your data (accessible through a property called, say, Model) and has additional properties, like a boolean IsVisible. INotifyPropertyChanged must be implemented by this class

If I copy and modify a template shown in the mentioned article:


        <!-- Level 0 template leaves space for 2 child "Toggle" levels -->
        <HierarchicalDataTemplate ItemsSource="{Binding Model.SubItems}">
            <Grid Visibility={Binding IsVisible, Converter={StaticResource B2VConverter}}>
                    <ColumnDefinition SharedSizeGroup="Task"/>
                    <ColumnDefinition SharedSizeGroup="Toggle"/>
                    <ColumnDefinition SharedSizeGroup="Toggle"/>
                    <ColumnDefinition SharedSizeGroup="Duration"/>
                    <ColumnDefinition SharedSizeGroup="Notes"/>
                <TextBlock Grid.Column="0" Text="{Binding Model.Task}" Style="{StaticResource TextBlockStyle}"/>
                <TextBlock Grid.Column="3" Text="{Binding Model.Duration}" Style="{StaticResource TextBlockStyle}"/>
                <TextBlock Grid.Column="4" Text="{Binding Model.Notes}" Style="{StaticResource TextBlockStyle}"/>

The new things are (I am unable to bold the text I added) the IsVisible property setting at the grid level and the data property references where 'Model.' has been added. It is bound to the new IsVisible property through a converter that you have to declare at the resources level:

Now, you modify your ViewModel when you want to hide or show an item in the tree. As simple as that. This is a rough introduction to the MVVM way of programming. You'll find lots of literature about it. It has quite a few advantages like the capability to unit test the UI logic (i.e. under which circumstances should a tree element become visible ?).

A simpler, less modular way to do what you request is to add the IsVisible property directly to the Model, but this is discouraged as on is mixing up apples and oranges. It may be OK for a very small program that is used for a couple of days and then thrown away.

Need Your Help

HTML/Java - How to restrict first 3 number of tel input field to specific number?

java html input tel input-type-file

I try to make registration site on wordpress that also required SMS phone verification. The problem is that my website is related to Pakistan. I also want to register users that are from Pakistan. ...

call RPGLE program from SQL within PHP / Zend Framework

php sql zend-framework call ibm-midrange

We have an AS400 RPGLE program created within the library LMTLIB, which is called ARTEST.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.