 |
|
 |
Hi
First of all, your article is so helpful! Good job!
I am trying to use this layout in a case where my treeview has more than one root (first-level) items, but I get their relative subtrees one on top the other. The must be something really small I'm missing, but I'm new to WPF and I was wondering if you can point me to the right direction.
Thanks
|
|
|
|
 |
|
 |
Awesome article as always! Great job.
I'm playing around with the sample and havent been able to render the items vertically instead of horizontally. Have you tried this layout?
Update:
Using Gideon Engelberth's suggestion, applying:
<TreeView.LayoutTransform>
<RotateTransform Angle="270" />
</TreeView.LayoutTransform>
Solves the initial layout, the only problem being that I somehow have to revent the layout transform at the "leef" node level, back to 90º. All and all, good stuff
Update:
Aha, re-reading the advanced treeview tutorial, I think I've found a way to make it all work, by checking the TreeViewItem.HasItems property and applying a different template, then resetting the transform.
I'll see if this works.
modified on Thursday, June 19, 2008 4:45 PM
|
|
|
|
 |
|
 |
I have spent 2 days of googling and listening presentations trying to learn more about WPF. If I correctly understood, WPF is used for making independent applications, wrote completely in XAML and it cannot be incorporated into existed VB.NET applications. Is that true?
I was looking for a way to implement skins into my application and it seemed to me that the WPF could be a nice way to do it. Am I on the right track or not?
|
|
|
|
 |
|
 |
virtual.aussie wrote: If I correctly understood, WPF is used for making independent applications, wrote completely in XAML and it cannot be incorporated into existed VB.NET applications. Is that true?
Well, it depends on what you mean by "existed VB.NET applications." If you are referring to a VB.NET WinForms app, you can use WPF controls there. If you mean ASP.NET apps, you can compile some WPF app into an XBAP and serve that up to the user.
WPF apps are not necessarily written only in XAML. You can use code if you want to. In fact, XAML is not at all necessary!
virtual.aussie wrote: I was looking for a way to implement skins into my application and it seemed to me that the WPF could be a nice way to do it.
I wrote an article about creating skinned UIs in WPF, check it out here[^].
:josh:
My WPF Blog[ ^]
Without a strive for perfection I would be terribly bored.
|
|
|
|
 |
|
 |
Hi,
I am wondering how do I add a new node to the tree.
As it is, it shows the whole structure, but does not allow to add a new node after it is initially loaded.
I want to add a node to the selected node in the tree.
I tried to add a node object to the ChildNodes generic list, but the treeview does not seem to see the changes. I cannot bind to the ItemsTemplate since the Node object does not have that kind of properties.
Any ideas?
|
|
|
|
 |
|
 |
Your question is not related to the subject of this article. Please post general WPF questions to Microsoft's WPF Forum[^]. Thanks.
:josh:
My WPF Blog[ ^]
Without a strive for perfection I would be terribly bored.
|
|
|
|
 |
|
 |
Hi,
I created a XAML tree and wants to set a selected Item explicitly. I tried couple of ways like by setting SelectedValuePath value but it is not showing a default selected node in expanded tree.
I was wondering if there is a way around to set this. Will really appreciate your help.
Thanks
Anshu
|
|
|
|
 |
|
 |
Try:
(iSender as TreeViewItem).IsSelected = true;
|
|
|
|
 |
|
 |
I tried this but the Item Type returned after selected a Node is TreeView type not TreeViewItems. so I was wondering if there is any other way around to set this explicitly.
Thanks
Anshu
|
|
|
|
 |
|
 |
My apologies. If you use the first parameter of the event you do indeed get the TreeView type. You can get the TreeViewItem object through the RoutedEventArgs.OriginalSource property. Usually this is a Visual inside of the TreeViewItem. If you go up the Visual tree you eventually get the TreeViewItem. This can be done in various ways, you can do it manually (like the example I have included) or, I believe, you can also use ItemsControl.ContainerFromElement, if you know the object that contains it in it's ItemsSource. Unfortunatly, since a TreeView is Hierarchical, you usually don't know this if the event is added to the TreeView itself. So for the TreeView, I use the VisualTreeHelper class to walk up the visual tree.
I have included the complete example this time, which should be more clearly. The event is the ContextMenuOpening event. Basically it makes certain that when the context menu is shown, the TreeViewItem is always selected (which doesn't happen automatically if the user only presses the right mouse button).
void ValuesTreeContextMenuOpening(Object aSender, ContextMenuEventArgs e)
{
DependencyObject iSender = e.OriginalSource as DependencyObject;
while (iSender != null && !(iSender is TreeViewItem))
{
iSender = VisualTreeHelper.GetParent(iSender);
}
if (iSender is TreeViewItem)
{
(iSender as TreeViewItem).IsSelected = true;
}
}
|
|
|
|
 |
|
 |
I need to have one node selected as default. is that possible in this tree view? it seems above examle i need user input.
|
|
|
|
 |
|
 |
Hello,
Thank you very much for the example, it did give a good start.
i tried modifying the above for my needs but I am stuck
I need to
- All nodes of the same size, centre aligned.
- Space between 2 node always should remain the same.
Regards
Sophia
|
|
|
|
 |
|
 |
If I understand you correctly, it sounds like you should use a DockPanel as the ItemsPanel for each TreeViewItem, not the StackPanel used in the demo app. Set the TreeViewItem Style to have the DockPanel.Dock attached property set to 'Top' so that all of the nodes are aligned with the center of their respective parent.
The space between nodes can be adjusted by tweaking the Margin and/or Padding properties on elements.
:josh:
My WPF Blog[ ^]
Donny: Are these the Nazis, Walter?
Walter Sobchak: No, Donny, these men are nihilists. There's nothing to be afraid of.
|
|
|
|
 |
|
 |
Hi,
Is it possible to make all the item the same size?
Also, how do I add a line between the items?
|
|
|
|
 |
|
 |
salsafyren2 wrote: Is it possible to make all the item the same size?
Yes, in the ControlTemplate there is a Border. Set it's Width and Height properties to some value. That will probably do the trick. Note, that will prevent the items from auto-sizing to their contents.
salsafyren2 wrote: Also, how do I add a line between the items?
This post[^] on the WPF forum shows how to do that.
:josh:
My WPF Blog[ ^]
We are what we repeatedly do. Excellence then, is not an act, but a habit. - Aristotle
|
|
|
|
 |
|
 |
Thanks.
I am new to WPF which seems a bit complex to me.
I would like to have lines which goes from treeviewitem to treeviewitem. The post uses rectangular lines, which does not fit my purpose.
I read about databinding here: http://msdn2.microsoft.com/en-us/library/aa480192.aspx
but I don't know how to databind a lines x1, y1,x2,y2 to the graphical representation of the treeviewitem. The line should go from the center of an item's bottom to the center of the top the child item.
If you know howto do that, I would appreciate it.
I read something here:
http://blogs.msdn.com/adrianvinca/archive/2006/03/07/SimpleGraphSample.aspx
but I am not sure how to translate that to my case.
|
|
|
|
 |
|
 |
Sorry, I don't know how to do what you are looking to do. I've haven't been down that path yet. If you figure it out, write an article about it and post it here on CP!
:josh:
My WPF Blog[ ^]
We are what we repeatedly do. Excellence then, is not an act, but a habit. - Aristotle
|
|
|
|
 |
|
|
 |
|
 |
Well done! That's a nice solution. Thanks for sharing it. Keep up the great work.
P.S. I tried to leave this comment on your blog, but, after clicking the submit button, it told me that I need to log in.
:josh:
My WPF Blog[ ^]
All of life is just a big rambling blog post.
|
|
|
|
 |
|
|
 |
|
 |
Same as all the above I couldn't agree more, great job
My question is where and how do I add events to the tree,
such as Click, RightClick etc.?
Can I make the tree behave like one, such as collapse node?
Cheers,
Gil
May the source be with you
|
|
|
|
 |
|
 |
You can handle the SelectedItemChanged event to know when an item has been clicked. All of the other input events should operate just fine, only the control's appearance was modified. If you want to be able to collapse a node you would need to add an expansion indicator to the TreeViewItem control template. I intentionally removed the expansion indicator because I didn't want it there.
Thanks for the feedback.
:josh:
My WPF Blog[ ^]
We are what we repeatedly do. Excellence then, is not an act, but a habit. - Aristotle
|
|
|
|
 |
|
 |
Thanks for the fast respond
I'll keep on playing around.
Gil
|
|
|
|
 |
|
 |
Nice take on a tree control, opens one's mind to far more options!
Also a nice tip!
It is sad about selecting an item though. At times I wonder if WPF is actaully V 0.5 as there appears to be a lot missing still. When I first started to play with WPF I was surprised by the lack of common controls such as a calendar combo for entering dates. I have found some from other sources, but I figure there will include a bunch more controls over the next year or so, or at least I hope
|
|
|
|
 |
|
 |
Thanks Rocky! I somewhat agree with your v0.5 comment. I think the urgency to finally release Vista forced WPF to be born prematurely, to a certain extent. Then again, there are sooo many cool things in WPF "v0.5" to learn, that noone will have time to learn the other half until it's released!!
Thanks again for the feedback. Much appreciated.
:josh:
My WPF Blog[ ^]
We are what we repeatedly do. Excellence then, is not an act, but a habit. - Aristotle
|
|
|
|
 |