|
thanks for the reply. can you provide an example code or syntax please ?
|
|
|
|
|
It's not a matter of coding or syntax it is your understanding of application design and how to construct an application.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a TreeView which I update it's ItemsSource property during runtime. The ItemsSource is assigned with multiple levels of data. During runtime I expand and collapse levels in the TreeView, but when I update the TreeView the expanded nodes are collapsed. Since I basically update the TreeView every time I select a node, to display it's child nodes, it gets very annoying to keep expanding the same nodes every time to watch the new level.
I understand why this is a issue for me because I set the ItemsSource property to null and than sets it with the proper data to update the TreeView's visualization. So of course all node are collapsed...
Here is an example of the code I use (It can be copied and pasted and tested right away):
<Window x:Class="Tree.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Tree"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TreeView Name="tvTree">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding SubNodes}" DataType="{x:Type local:Node}">
<Grid>
<TextBlock Text="{Binding Header}" />
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<Button Content="Button" Height="50" HorizontalAlignment="Left" Margin="456,263,0,0" Name="button1" VerticalAlignment="Top" Width="47" Click="button1_Click" />
</Grid>
</Window>
The C# behind it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Tree
{
public partial class MainWindow : Window
{
Node top;
Node root;
public MainWindow()
{
InitializeComponent();
root = new Node();
root.Header = "Root";
root.SubNodes.Add(new Node("B1"));
top = new Node();
top.SubNodes.Add(root);
Update();
}
public void Update()
{
tvTree.ItemsSource = null;
tvTree.ItemsSource = top.SubNodes;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
root.SubNodes.Add(new Node("B2"));
Update();
}
}
public class Node
{
List<Node> subNodes = new List<Node>();
string header;
public Node()
{
}
public Node(string header)
{
this.header = header;
}
public string Header
{
get { return header; }
set { header = value; }
}
public List<Node> SubNodes
{
get { return subNodes; }
set { subNodes = value; }
}
}
}
I use the button to add new data into the TreeView. Notice the Update() method which updates the TreeView's ItemsSource.
Can I in some way expand the nodes in the TreeView after I have changed the ItemsSource? I can keep track of which nodes are expanded or not (I left out that code in the example). I know about the .IsExpanded property in the TreeViewItem class, but in my case I don't have TreeViewItem in my ItemsSource so therefore I don't have any .IsExpanded property to use.
In some way I feel this approach maybe not be the best. Especially how I update the TreeView item. If there are any other way please tell me and tell me how.
|
|
|
|
|
Change you List<node> to an observablecollection<node> (reference system.collections.objectmodel) and comment out the update method after adding a node!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Seems to be working Thanks!
|
|
|
|
|
Using the right tools makes a huge difference, the observable collection and the onpropertychange wire up is what makes xaml binding work.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I would like to purchase an apple mac laptop for learning and developing in:
1- visual studio express 2010 i.e. silverlight/wpf
2- sql server express 2008
3- Winidows phone 7
Is it possible to install the above softwares on apple mac laptop please?
Thanks
|
|
|
|
|
You will have to install windows on your mac first either via a virtual machine or boot camp http://support.apple.com/kb/ht1461
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
|
|
|
|
|
|
If your only reason to buy a laptop is to learn everything there is to know about visual studio, silverlight, wpf, WP7,... why on earth would you consider a mac?
|
|
|
|
|
Hi all, I am new to silverlight. I am a ASP.NET developer. I have to work on a project in which DevExpress Controls and Silverlight is used but i have only initial level undersatnding. Lots of work needs to be done on DevExpress Grid Control and it will be a copmlex grid in which data coming from different sources.Apart from this WCF RIA and Entity framework is being used. Please help me out to solve the devexpress grid finctioality in silvelight and please suggest me what are the best approaches to get familiar with these as soon as possible.
Thanks
|
|
|
|
|
Check out the help and documentation on the grid here[^].
There are a few demos available as well.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Hi;
I have been wrestling with microsoft's changing standards and technologies like many of us. with that I was really not prepaired when silverlight 3/4 came out and WPF. I'm a winforms guy.
So I have been looking for an example of a project that will show me how to use an MVVM pattern with WPF with an Icommand in it. That may seem trivial to most here. but I just have allot of problems with the databinding concepts and the viewmodels. I would like to create a control that I can host in a window that is XAML and have that control connected to a viewmodel and use ICommand for the clicks and such. Everyone adds their own classes and it seems to clutter up the core concept for a rookie. I would like to use a WCF service to fill the UI with data and back and forth. Can someone furnish me with some info on this. this may need a couple of tutorials or just one good one to get me off to the races. I want to use the ICommand so that I will be able to use some of that MVVMness with Silverlight 4.
I thank you in advance for your help.
Blessings and regards
-Peter
|
|
|
|
|
|
Not that its going to help you, but I've NEVER seen a good MVVM tutorial. They are all WAY too complicated and try to introduce too many concepts at once. If you don't get data binding concepts with writing non-MVVM code, I'd start there. MVVM is only going to confuse you more. Next step would probably be to learn how to use RelayCommand and RelayCommandT in non-MVVM code. Honestly though, you'll need an MVVM framework cuz you can't do MVVM with .Net out of the box, you need a lot of support infrastructure first.
|
|
|
|
|
Honestly though, you'll need an MVVM framework cuz you can't do MVVM with .Net out of the box, you need a lot of support infrastructure first.
I completly disagree. I do MVVM apps all the time and I strt from scratch. Once you understand some basics, it's really not that hard.
MVVM is just a pattern. Most competant programmers are already conforming to some patter, whethere it's n-tier or something else.
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: I do MVVM apps all the time and I strt from scratch
Yeah but I bet you have a bunch of tools/utilities/styles etc. I know I have and you could almost call them a framework.
I started off with MVVM light but we kept extending the dammed thing with stuff we need specific to our style. Starting a new project is a bitch, you need to chase around and get all the really useful bits from the last project(s). We now have most of them in a single utilities project but it keeps changing!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
... because its awesome to have 50 copies of all your classes strewn across 100 projects and have all the different versions be different 6 months down the road rather then put it in a reusable library .
I don't use any of the "popular" MVVM frameworks like MVVM light, Cinch, etc... but I do have a framework that I put together myself... c&p'ing code repeatedly is just silly.
|
|
|
|
|
SledgeHammer01 wrote: c&p'ing code repeatedly is just silly
I just wish I could put styles in a central, reusable project like I can with code.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why can't you? I do this all the time. You basically create an assembly full of resource dictionaries.
|
|
|
|
|
So every time you write a new MVVM app, you write the following from scratch:
1) RelayCommand and RelayCommand<T>?
2) ViewModelBase?
3) a Messenger service to communicate between ViewModels?
4) a ViewLocator?
5) a dialog service?
Aside from the above obvious "required" stuff, you also usually need:
1) some way to map events to commands
2) a DI container
3) lots of other little things here and there... for example a way to bind to DialogResult, a way to bind to multi-select list controls, etc.
Thats just off the top of my head...
|
|
|
|
|
Have you read my series of articles? (See my sig for a link)
I didn't use a framework, just a couple of classes that make things easier, and the example as a whole is, I think, about as simple as it can get and still be real enough to be more than a trivial "Hello World"
It's WPF - but converting to Silverlight is pretty easy if you need to.
|
|
|
|
|
In 95% of projects MVVM adds another degree of complication that is simply not necessary. For what? To separate the UI from business logic? You are probably doing this anyway. For automated testing? I fail to see how automated testing can test anything but the simplest of scenarios.
Check the excellant tutorials on the Silverlight site to get started. Look into entity framework (EF) and Domain Services to generate code for backend database access. Use one of the business application templates to stub out a new project with styling. Avoid MVVM unless you are working on a team of dozens.
|
|
|
|
|
Glosse wrote: In 95% of projects
Did you know that 78% of statistics on the internet are just made up?
Glosse wrote: I fail to see how automated testing can test anything but the simplest of scenarios.
Then you're doing it wrong
Have you ever actually developed an MVVM project?
I rather tend to agree that there are many cases where MVVM would be overkill if you were just going to use it for a single small project. But if you develop using MVVM for everything, it becomes second nature, and you start thinking in MVVM terms. It is massively helpful in large teams, or when the gui design may change (i.e. you have customers) but there's no reason to avoid it in any size team (from 1 up) - at the very least, once you know the pattern and are familiar with your way of doing it, there's no disadvantage.
|
|
|
|
|
I'm on a 1 1/2 man team and have written WPF projects using both MVVM and non MVVM ways. The non MVVM projects are complete clusterf**ks in terms of code organization. Everything is hacked together with duct tape and chicken wire. I then developed my own MVVM framework (the right way) and wrote a few projects using it. The code is MUCH cleaner, MUCH more elegant, there are very few "cheezy hacks" and there is no duct tape and chicken wire holding things together. Thats the biggest advantage of MVVM IMO. The biggest PROBLEM IMO is getting a framework together that actually allows you to do MVVM properly. Theres much, much, much more to doing proper MVVM then just having a RelayCommand<T> implementation that you C&P everywhere. Once you've done a few MVVM projects (the right way) and have it all fleshed out, the next project is much easier since you've already solved all the typical MVVM problems and of course put it all together in a reusable framework.
|
|
|
|