Click here to Skip to main content
15,896,063 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Need Help: Is it possible to create such ComboBox UI? Pin
SledgeHammer017-Jan-11 17:55
SledgeHammer017-Jan-11 17:55 
GeneralRe: Need Help: Is it possible to create such ComboBox UI? Pin
Kunal Chowdhury «IN»9-Jan-11 3:45
professionalKunal Chowdhury «IN»9-Jan-11 3:45 
GeneralRe: Need Help: Is it possible to create such ComboBox UI? Pin
Kunal Chowdhury «IN»10-Jan-11 1:26
professionalKunal Chowdhury «IN»10-Jan-11 1:26 
QuestionTreeViewItem Binding Doubt Pin
AmitDey6-Jan-11 6:51
AmitDey6-Jan-11 6:51 
AnswerRe: TreeViewItem Binding Doubt Pin
SledgeHammer016-Jan-11 8:14
SledgeHammer016-Jan-11 8:14 
GeneralRe: TreeViewItem Binding Doubt Pin
AmitDey7-Jan-11 6:17
AmitDey7-Jan-11 6:17 
GeneralRe: TreeViewItem Binding Doubt Pin
SledgeHammer017-Jan-11 7:55
SledgeHammer017-Jan-11 7:55 
AnswerRe: TreeViewItem Binding Doubt Pin
Ian Shlasko7-Jan-11 9:03
Ian Shlasko7-Jan-11 9:03 
I think you're going about this the wrong way... Yes, you can work directly with the TreeView, but that's not how it's supposed to be used. The idea is to do everything via data-binding, so you never have to touch the TreeView or TreeViewItems at all.

Here's how I would go about this:

1) Add a "Children" property to your Item (Can call it whatever you want), typed as, say, an ObservableCollection<Item>. You may also want to create boolean properties such as "IsExpanded" and "IsSelected", which can be bound in the TreeView.ItemContainerStyle.

2) As another poster suggested, implement INotifyPropertyChanged on your Item class, and make sure you're raising the PropertyChanged event when the Text property changes.

3) Use a HierarchicalDataTemplate in your XAML... This is basically a DataTemplate that also has an ItemsSource property to include children... Something simple, like:
XAML
<HierarchicalDataTemplate DataType="{x:Type local:Item}" ItemsSource="{Binding Children}">
	<TextBox Text="{Binding Text}"/>
</HierarchicalDataTemplate>

(You can expand on it later)

4) Set the ItemsSource property of your TreeView to the root node of your tree. It'll automatically generate the rest of the nodes as you modify your Item and its children.

Now, when you want to add another node under your root, just pop one into the Children collection, and the TreeView will detect this and update itself. Basically, you should never have to touch the TreeViewItems directly.
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)

Questionsilverlight 4- which rows are updated with checkbox. [modified] Pin
arkiboys5-Jan-11 22:59
arkiboys5-Jan-11 22:59 
AnswerRe: silverlight 4- which rows are updated with checkbox. Pin
Pete O'Hanlon5-Jan-11 23:38
mvePete O'Hanlon5-Jan-11 23:38 
GeneralRe: silverlight 4- which rows are updated with checkbox. Pin
arkiboys5-Jan-11 23:43
arkiboys5-Jan-11 23:43 
QuestionParent, Child & GrandChild binding in WPF & Silverlight Pin
Chazzysb5-Jan-11 4:33
Chazzysb5-Jan-11 4:33 
AnswerRe: Parent, Child & GrandChild binding in WPF & Silverlight Pin
Abhinav S6-Jan-11 1:08
Abhinav S6-Jan-11 1:08 
GeneralRe: Parent, Child & GrandChild binding in WPF & Silverlight Pin
Chazzysb6-Jan-11 3:55
Chazzysb6-Jan-11 3:55 
QuestionHow can I create layout in the following way? Pin
Pankaj Nikam4-Jan-11 23:36
professionalPankaj Nikam4-Jan-11 23:36 
AnswerRe: How can I create layout in the following way? Pin
#realJSOP6-Jan-11 2:16
professional#realJSOP6-Jan-11 2:16 
GeneralRe: How can I create layout in the following way? Pin
mbcrump12-Jan-11 4:34
mentormbcrump12-Jan-11 4:34 
QuestionValidation for Duplication of Data by using Identifier name Pin
Rocky234-Jan-11 22:42
Rocky234-Jan-11 22:42 
AnswerRe: Validation for Duplication of Data by using Identifier name Pin
Pete O'Hanlon4-Jan-11 23:34
mvePete O'Hanlon4-Jan-11 23:34 
GeneralRe: Validation for Duplication of Data by using Identifier name Pin
Rocky234-Jan-11 23:49
Rocky234-Jan-11 23:49 
GeneralRe: Validation for Duplication of Data by using Identifier name Pin
Pete O'Hanlon5-Jan-11 0:41
mvePete O'Hanlon5-Jan-11 0:41 
Questionhow to export the WindowsFormsHost content in to pdf formate Pin
Member 41595674-Jan-11 20:18
Member 41595674-Jan-11 20:18 
Questionhow to generate tree view in MVVM- silverlight Pin
silverlightnewbee4-Jan-11 17:51
silverlightnewbee4-Jan-11 17:51 
AnswerRe: how to generate tree view in MVVM- silverlight Pin
Abhinav S4-Jan-11 18:30
Abhinav S4-Jan-11 18:30 
QuestionWCF Service and event [modified] Pin
CrafterIt4-Jan-11 0:03
CrafterIt4-Jan-11 0:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.