|
|
Karl, that example is lazing loading a filesystem view into a treeview which is the opposite of what I'm doing.
This is more a question about the treeview expander/collapser than about the task shown in the screenshots. Please take another quick look at this code, ignoring the C:\.
TreeNode tn1 = new TreeNode(@"C:\");<br />
TreeNode tn2 = new TreeNode(@"C:\");<br />
TreeNode tn3 = new TreeNode(@"C:\");<br />
<br />
TreeNodeList.Add(tn1);
<br />
tn1.Children.Add(tn2);<br />
tn1.Children.Add(tn3);<br />
<br />
TreeNodeList.Add(tn1);
The first Add(tn1) produces an item with no expander. The 2nd does.
|
|
|
|
|
artwallacex wrote: TreeNodeList.Add(tn1); // Produces item with no expander!
I think this is because there are no child TreeNodes and WPF is working correctly. After adding a child, the expander shows up.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
But there are two child treenodes created by:
tn1.Children.Add(tn2);
tn1.Children.Add(tn3);
They show up in the UI and if you doubleclick on the parent they will be displayed. The problem is the collapser is not drawn but the child elements are there.
|
|
|
|
|
TreeNodeList.Add(tn1);
tn1.Children.Add(tn2);
tn1.Children.Add(tn3);
TreeNodeList.Add(tn1);
The first line of code TreeNodeList.Add(tn1); // Produces item with no expander! has no children at that point in time.
The second line does.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
So you're saying that the databinding is not supposed to take care of that? The child nodes must be added before the parent item is added to the list?
And again, running this code:
TreeNodeList.Add(tn1); // Produces item with no expander!
tn1.Children.Add(tn2);
tn1.Children.Add(tn3);
without the 2nd Add will still show all of the child elements, just without the expander. Double clicking the parent item will draw the child elements and the parent & children will produce events just like the others in the list.
modified on Thursday, April 3, 2008 12:27 PM
|
|
|
|
|
I think the problem is, I'm not looking at the same code you are.
Can you post all the code?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Sure, here's the solution in a 100k zip file.
http://www.crankedup.com/misc/wpf-treeview-notriangle.zip[^]
When you launch it, press the "Fake" button.
It now calls this code:
TreeNode tn1 = new TreeNode("1");<br />
TreeNode tn2 = new TreeNode("2");<br />
TreeNode tn3 = new TreeNode("3");<br />
TreeNode tn4 = new TreeNode("4");<br />
TreeNode tn5 = new TreeNode("5");<br />
<br />
TreeNodeList.Add(tn1);<br />
<br />
tn1.Children.Add(tn2);<br />
tn1.Children.Add(tn3);<br />
<br />
tn2.Children.Add(tn4);<br />
tn2.Children.Add(tn5);
And produces this screenshot (I've expanded all the nodes in the shot):
http://www.crankedup.com/misc/wpf-treeview-notriangle3.png[^]
PS- Thanks for taking a little time to look at this.
|
|
|
|
|
Moved the adding of tn1 to the bottom and it works great.
private void button3_Click(object sender, RoutedEventArgs e)
{
DirectoryInfo junkDir = new DirectoryInfo(@"C:\");
TreeNode tn1 = new TreeNode("1");
TreeNode tn2 = new TreeNode("2");
TreeNode tn3 = new TreeNode("3");
TreeNode tn4 = new TreeNode("4");
TreeNode tn5 = new TreeNode("5");
tn1.Children.Add(tn2);
tn1.Children.Add(tn3);
tn2.Children.Add(tn4);
tn2.Children.Add(tn5);
TreeNodeList.Add(tn1);
}
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Yes, I know.
But I've yet to see anything that suggests it shouldn't work the other way. To me it looks like a bug in the TreeView.
|
|
|
|
|
I found the solution.
First put this back back the way it was.
private void button3_Click(object sender, RoutedEventArgs e)
{
DirectoryInfo junkDir = new DirectoryInfo(@"C:\");
TreeNode tn1 = new TreeNode("1");
TreeNode tn2 = new TreeNode("2");
TreeNode tn3 = new TreeNode("3");
TreeNode tn4 = new TreeNode("4");
TreeNode tn5 = new TreeNode("5");
TreeNodeList.Add(tn1);
tn1.Children.Add(tn2);
tn1.Children.Add(tn3);
tn2.Children.Add(tn4);
tn2.Children.Add(tn5);
}
Modify the TreeNode class as below.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace WpfTest
{
public class TreeNode
{
private string dir = "";
private ObservableCollection<TreeNode> children = new ObservableCollection<TreeNode>();
private List<string> files = new List<string>();
public TreeNode(string directory)
{
dir = directory;
}
public string Dir
{
get { return dir; }
set { dir = value; }
}
public ObservableCollection<TreeNode> Children
{
get { return children; }
set { children = value; }
}
public List<string> Files
{
get { return files; }
set { files = value; }
}
}
}
Your all done.
You may want to do the same to the Files collection also.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Doh, very good catch.
Unfortunately my real project is using an ObservableCollection with the proper using statements. The List<> is something I forgot or either experimented with in my sample project.
So the sample project now works correctly so I'm back to hunting in my code.
Thanks for your help Karl.
Edit- My real project has the same problem. The collection bound to the list is an ObservableCollection but the children are just Lists, like in the sample. So double thanks Karl, you were spot on.
modified on Thursday, April 3, 2008 1:49 PM
|
|
|
|
|
Glad to help out.
I'm a VB.NET geek so digging into the C# code is good for me.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Heh, it was funny that you posted your TreeView article at the beginning of this thread. It was through that article that I read your mentoring article, which was what got me trying to nail down the problem in this sample application (mentorees "Do your own homework"/"forces you to study and carefully review your topic")!
It's a small world.
|
|
|
|
|
This means we are having a good day then.
The homework business normally translates to, "please check Google, then post question."
Just glad we got you on the right track.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi all,
I'm fiddling around with WPF quite a bit, but i can't seem to get this working:
I want four controls in a horizontal row (expanders in this case) to each have 1/4 (25%) of the width of the entire screen (so horizontally they fill up the whole screen, even when resizing..)
But here's the catch, the expanders are filled with icons, so when i set width to auto, the expander gets the width depending on how many icons (images) are in the expander's content..
I tried using a grid with colums, but i didnt find out how to set the width to 25% of each column, is there ven a way to do this? Or does another control do what i want? Also tried a stack/wrappanel, but it didnt work out..
Thx
|
|
|
|
|
Would a UniformGrid work for you there?
|
|
|
|
|
I just read something about this, will see if it works, thx!
/does exactly the same as a normal grid..
Example of what im doing:
<br />
<br />
<grid><br />
<br />
<expander content="{Staticresource somecontent}" /><br />
<Expander content="{Staticresource somecontent2}" /><br />
<Expander content="{Staticresource somecontent3}" /><br />
<Expander content="{Staticresource somecontent4}"/><br />
<br />
</grid><br />
The resource content is something like this:
<br />
<image /><br />
<image /><br />
<image /><br />
...<br />
<image /><br />
Each expander resizes now to the amount of content (images) in them, which is different for each 1..
Found a solution:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=ColumnDefinitions[0].Width}" />
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=ColumnDefinitions[1].Width}"/>
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=ColumnDefinitions[2].Width}"/>
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=ColumnDefinitions[3].Width}"/>
</Grid.ColumnDefinitions>
modified on Friday, April 11, 2008 3:48 AM
|
|
|
|
|
|
Michael,
Thanks for this post.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
|
thanks. I saw your post in Silverlight forum.. I will add your link in my post too.
|
|
|
|
|
Thanks!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi All,
I'm just doing some work in DirectX and have a referencing question. Using this method on a device needs a handle to the main apps window the problem with that was my directX layer was referenced by the presentation layer so to actually set this to my apps mainwindow class i've had to reference the presentation layer from the audiolayer ...
Does it actually make sense to reference this way around or is there a better solution to this issue?
This is a WPF window and unlike WinFOrms (as far as I can tell) this isn't showing me a Handle property to specify, any advice on that would be great.
EDIT -
Have been doing a bit more digging at it seems that my fix is the way to go. Since WPF windows are essentially DirectX setting the SetCooperativeLevel to System.IntPtr.Zero is the way to go ...
Has anyone else done any DirectX work with WPF yet?
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
As I understand it, WPF is basically a DirectX wrapper for .NET. I don't believe that native DirectX can be combined with WPF Direct X and have them cooperate with each other. Good luck either way.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|