|
I've been looking through animation tutorials for WPF and they all seem to use the "RoutedEvent" inside an event trigger that is hooked up to the form loading or a button being pressed....
But how would I, say, launch an animation when my SQL query has finished or when a file has finished loading, etc, etc.
Is there just some simple "Do this animation now" command I can call on a story board??
Thanks.
|
|
|
|
|
|
Hi.
I have a class library with a class that requires a dependanct property to be included. So I've referenced WindowsBase and inserted Using System.Window.
I've used the following code to set up the dependancy property:
<br />
public bool IsChecked<br />
{<br />
get { return (bool)GetValue(IsCheckedProperty); }<br />
set { SetValue(IsCheckedProperty, value); }<br />
}<br />
<br />
public static readonly DependencyProperty IsCheckedProperty =<br />
DependencyProperty.Register("IsChecked", typeof(bool), typeof(EdgeProperty), new UIPropertyMetadata(false));<br />
<br />
I can see that the DependencyProperty class is referenced and all is fine. However, the methods 'GetValue' and 'SetValue' do not exist. I know these are from the DependancyObject class, which is referenced.
Anybody know what's going on?
Cheers,
Chris
|
|
|
|
|
What does your class inherit from?
|
|
|
|
|
Chris,
Using Visual Studio, add a new project to your solution, a WPF Custom Control library.
After you create it, you can delete the Themes folder and the custom control it creates by default.
Now move your class into this project and everything will work fine.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
You need to inherit from DependencyObject not just reference it.
|
|
|
|
|
Cheers guys, that worked.
|
|
|
|
|
Hi,
I hope someone can help me understand what is going on with WPF TreeView binding.
My project has been having some weird issues with treeviews bound to a recursively created collection. The problem is that some nodes haven't had an expander/collapser triangle even though they still have subnodes (they can be doubleclicked to expand/collapse though).
Here are two small pictures of the issue I'm having:
http://www.crankedup.com/misc/wpf-treeview-notriangle.png[^]
http://www.crankedup.com/misc/wpf-treeview-notriangle2.png[^]
The second pic is the expanded version of the first one.
The code that created this is:
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 treenode class is the standard stuff:
public class TreeNode<br />
{<br />
private string dir = "";<br />
private List<treenode> children = new List<treenode>();<br />
public TreeNode(string directory)<br />
{<br />
dir = directory;<br />
}<br />
public string Dir<br />
{<br />
get { return dir; }<br />
set { dir = value; }<br />
}<br />
public List<treenode> Children<br />
{<br />
get { return children; }<br />
set { children = value; }<br />
}<br />
}
And the XAML binding was taken from examples I've seen on the web:
<Window.Resources><br />
<HierarchicalDataTemplate DataType="{x:Type local:TreeNode}" ItemsSource="{Binding Path=Children}"><br />
<StackPanel Orientation="Horizontal"><br />
<Image Source="Graphics\folder.png" /><br />
<TextBlock Text="{Binding Path=Dir}" Margin="5,0" /><br />
</StackPanel><br />
</HierarchicalDataTemplate><br />
</Window.Resources><br />
<br />
<TreeView HorizontalAlignment="Left" Margin="8,9,0,38" Name="treeView1" Width="188" ItemsSource="{x:Static local:Window1.TreeNodeList}" />
What am I doing wrong here?
modified on Thursday, April 3, 2008 4:50 AM
|
|
|
|
|
|
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?
|
|
|
|