|
I've used a separate 'controller' class for this kind of scenario.
Let the viewmodel know about this controller class and then let this 'controller' or 'loader' class decide which view needs to be loaded.
Decouples the viewmodel from all the views.
|
|
|
|
|
MVVM doesn't have a controller. Also, it already has a mechanism for mapping VMs to Views... DataTemplates.
|
|
|
|
|
SledgeHammer01 wrote: MVVM doesn't have a controller
I agree. But you can always build one.
You can call it controller or view loader or whatever you like.
The idea is to decouple the viewmodel from the logic of instantiating the appropriate view.
|
|
|
|
|
Yeah, thats what DataTemplates do .
|
|
|
|
|
Been messing around with this all day and its not working for some reason. I know as you expand a node, you have to wait for the ItemContainerGenerator to do its thing, which is what I'm doing, but its only expanding one level for some reason:
internal void ExpandAll(TreeViewItem tvi)
{
if (tvi.IsExpanded)
{
for (int nIndex = 0; nIndex < tvi.Items.Count; nIndex++)
{
TreeViewItem tviCurrent = tvi.ItemContainerGenerator.ContainerFromIndex(nIndex) as TreeViewItem;
if ((object)tviCurrent != null)
ExpandAll(tviCurrent);
}
}
else
{
if (tvi.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
{
EventHandler handler = null;
handler = new EventHandler(delegate
{
if (tvi.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
{
ExpandAll(tvi);
}
});
tvi.ItemContainerGenerator.StatusChanged += handler;
}
tvi.SetCurrentValue(TreeViewItem.IsExpandedProperty, true);
}
}
So I only get inside the EventHandler one time. It doesn't get in there for the child nodes. If I expand the child node manually, THEN the handler code is called.
Also tried the built in .Net ExpandSubTree and it has the same issue. Only expands one level down.
I don't think I'm intercepting anything anywhere.
|
|
|
|
|
I used this article [^]as the basis of my treeview item, it binds the IsExpanded to a property and that drives the tree. I extended it somewhat to meet my needs but it was an excellent concept and worked very well.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah, I have support for binding the IsExpanded property to a property in the data object in my customized TreeView control, but... I dunno... just seems like a hokey requirement to require the user of my control to maintain item state. My custom TreeView control also has built in support for displaying checkboxes next to each item. I can see binding the checkbox to a property in the data object since that kind of seems like a legit requirement. If the user is using checkbox mode, he is going to want to know the checked state of each item. He isn't really going to care about whether a node is expanded or not. Now he *might* if he wants to save the tree state, so I definitely want to keep that as an option, but I was trying to avoid relying on that to make the treeview work in general.
|
|
|
|
|
I have a tag on this discussion at telerik [^]and thought it may be relevant to your issue
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
The WPF toolkit on codeplex has a very good auto complete text box. Just google it as I haven't figured out how to copy paste on my tablet yet, sorry.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Can someone point me to a decent tutorial on how to override a WPF TextBox? I tried Googling, but the answers are all over the board. not sure what I'm looking for. I just want to add various functionality, and I'm looking for a starting point
If it's not broken, fix it until it is
|
|
|
|
|
This MSDN paper[^] explains the basics. You just need to add the parts that are specific to your needs.
Use the best guess
|
|
|
|
|
If you think you need to override a WPF control, you are almost always wrong. WPF allows you to attach behaviour to existing controls using Blend Behaviors.
|
|
|
|
|
Well, Like I said, I'd like to add functionality that's not there, so I don't know how that means I'm wrong. It's really extending the textbox that I want. I just don't know how to do it in WPF.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
In WPF, it's normal to prefer composition over inheritance. Here's[^] an example of extending the TextBox without actually doing any overriding. This is a very powerful technique.
|
|
|
|
|
How can I limit the length of text entered into a textbox?
I am using WPF Extended Toolkit. Not sure if there's a property on the textbox there to do it.
If it's not broken, fix it until it is
|
|
|
|
|
If there is not a property on the textbox you can always detect the opropertychanged event and deal with it in the VM, you could set up a behaviour (not sure this fires OPC)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
TextBox has a MaxLength associated with it.
|
|
|
|
|
I have been hearing about Prism. I'm curious how popular it is, and is it worth taking the time to learn. I have heard that it's complex.
1) How many of you are actually using it?
2) Should I start learning it?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The guys associated with the prism project released a book called 'Developer's Guide to Microsoft Prism'. It was released as a free PDF so don't pay for it unless you want the hardcopy. (Look in the table at the 'Downloads' section on http://msdn.microsoft.com/en-us/library/gg406140.aspx[^]) I suggest you read it even if you don't end up doing anything with Prism.
Prism is the ultimate MVVM toolbox. It has everything which makes it much heavier than something like MVVM Light. Which is why you should read the book and understand the advantages and disadvantages of the framework. In short, where something like MVVM Light is designed to help you build an application that follows the MVVM pattern by providing resources that make the task easier, Prism is designed for building composite applications using the MVVM pattern. That is an important difference.
Like many other frameworks and patterns, you can pick and choose what you want to include so while the whole shooting match is pretty big, you don't have to use all of it. I like it, especially for large projects where the ability to break the resulting app into modules that are located and loaded at runtime provides a big advantage. But I also use MVVM Light a lot as well when I don't need the horsepower Prism provides and I just want the MVVM pattern.
Regardless of whether you ultimately end up using it, you should probably learn about it. At least then you would be able to recognize on your own when it could/should be used rather than relying on the infamous 'I have heard...' decision making process.
|
|
|
|
|
Wow,. Fantastic response. Thank you!!!
If it's not broken, fix it until it is
|
|
|
|
|
The code used in populating combobox is as <DataGridTemplateColumn > <DataGridTemplateColumn.CellTemplate> <DataTemplate >
<ComboBox x:Name="dd" DisplayMemberPath="district" ItemsSource="{Binding Source={StaticResource districtViewSource}}" ></ComboBox> </DataTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
THE PROBLEM IS THAT WHEN I SELECT A PARTICULAR ITEM IN COMBO EVERY COMBOBOX IN ABOVE COLUMN IE IN ALL ROWS AUTOMATICALLY SELECTS THAT ITEM. WHILE IT MUST BE ANOTHER ITEM FOR REMAINING ROWS.
|
|
|
|
|
All caps is the equivalent of shouting - very rude!
You are using the same collection districtViewSource for all the combos, create a copy of the collection and a selecteditem for each combo.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello All,
I have created a webpage and trying to integrate a Silverlight control with it. Unfortunately I am getting an error.
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="OnlineEntertainment.Web.WebForm1" %>
<%@ Register Assembly = "System.Web.Silverlight" Namespace="Syste.Web.UI.SilverlightControls" TagPrefix="asp" %>
<%@ Register Assembly = "AjaxConrolToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Silverlight ID="Silverlight1"
Source="C:\Users\Hunter\Documents\Visual Studio 2010\Projects\OnlineEntertainment\OnlineEntertainment.Web\ClientBin"
runat="Server" Height="805px" Width="623px"> </asp:Silverlight>
</asp:Content>
Element 'Silverlight' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.
Is there any specific reason ? I have tried to search for the reference System.Web.Silvelrlight.DLL but it was not present.
I am using Silverlight 5 and Visual Studio 2010.
Thanks and Regards
Anurag
|
|
|
|
|