SilverlightShow: Make the TreeView control to be MVVM compliant Comments
http://www.silverlightshow.net/
Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samplesSilverlightShow.nethttp://www.rssboard.org/rss-specificationArgotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argoticen-USestoychev@completit.com (Emil Stoychev)Re: Make the TreeView control to be MVVM compliant<p>ok, i think i figured it out. i coded a simple helper class derived from INotifyPropertyChanged and bound it to the TextBox - may be i've got something wrong, but i thought the notification behaviour would be automatically be added because ViewModel is indirectly derived from it???</p>
<p> public class HierarchicalViewModelNotifier : INotifyPropertyChanged<br />
{<br />
private HierarchicalViewModel<CMSSTRUCT> _currentViewModel = null;<br />
public HierarchicalViewModel<CMSSTRUCT> CurrentViewModel { get { return _currentViewModel; } set { _currentViewModel = value; Changed("CurrentViewModel"); } }<br />
public event PropertyChangedEventHandler PropertyChanged;<br />
private void Changed(string propertyName)<br />
{<br />
if (PropertyChanged != null)<br />
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));<br />
}<br />
}</p>
<p> public class MainPageViewModel : ViewModel<br />
{</p>
<p>public HierarchicalViewModelNotifier ViewModelNotifier { get; set; } </p>
<p>...</p>
<p>public MainPageViewModel()<br />
{<br />
ViewModelNotifier = new HierarchicalViewModelNotifier();<br />
ViewModelNotifier.CurrentViewModel = Root.FirstOrDefault(); </p>
<p>...</p>
<p>}</p>
<p>private void ClickItem(HierarchicalViewModel<CMSSTRUCT> item)<br />
{<br />
ViewModelNotifier.CurrentViewModel = item;<br />
} </p>
<p> and in the XAML i did it like this way:</p>
<p><TextBox Grid.Column="2" Grid.Row="1" Height="23" HorizontalAlignment="Left" Name="textBoxText" VerticalAlignment="Top" Width="280" Text="{Binding ViewModelNotifier.CurrentViewModel.PayLoad.CMSSTRUCT_NAME, FallbackValue='Selektion konnte nicht ermittelt werden!', Mode=TwoWay}" /></p>
<p>so let's look where i might stuck next ;o) </p>
<p></p>
<p></p>
<p> </p>
<p></p>
<p> </p>
http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspx#comment7317
rookie07http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspxMon, 19 Dec 2011 17:20:33 GMTRe: Make the TreeView control to be MVVM compliant<p>very nice article!</p>
<p>i'm getting slowly into the mvvm thing...so there is still a problem which i have to solve. supose i want to bind a TextBox.Text to the ItemClickedCommad how to get this done?</p>
<p> i added a propety to the MainPageViewModel like:</p>
<p>public HierarchicalViewModel<CMSSTRUCT> CurrentViewModel { get; set; } </p>
<p>in order to connect the data to the event: </p>
<p> private void ClickItem(HierarchicalViewModel<CMSSTRUCT> item)<br />
{<br />
CurrentViewModel = item;<br />
}</p>
<p> </p>
<p>in the XAML i thought i could do something like:</p>
<p> <TextBox Grid.Column="2" Grid.Row="1" Height="23" HorizontalAlignment="Left" Name="textBoxText" VerticalAlignment="Top" Width="280" Text="{Binding CurrentViewModel.PayLoad.CMSSTRUCT_NAME, FallbackValue='loding failed!'}" /></p>
<p>but it seems that the textbox is never updated...? what am i doing wrong?</p>
<p>thanx!</p>
<p></p>
<p></p>
<p> </p>
http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspx#comment7316
rookie07http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspxMon, 19 Dec 2011 16:46:16 GMTRe: Make the TreeView control to be MVVM compliant<p>very nice article!</p>
<p>i'm getting slowly into the mvvm thing...so there is still a problem which i have to solve. supose i want to bind a TextBox.Text to the ItemClickedCommad how to get this done?</p>
<p> i added a propety to the MainPageViewModel like:</p>
<p>public HierarchicalViewModel<CMSSTRUCT> CurrentViewModel { get; set; } </p>
<p>in order to connect the data to the event: </p>
<p> private void ClickItem(HierarchicalViewModel<CMSSTRUCT> item)<br />
{<br />
CurrentViewModel = item;<br />
}</p>
<p> </p>
<p>in the XAML i thought i could do something like:</p>
<p> <TextBox Grid.Column="2" Grid.Row="1" Height="23" HorizontalAlignment="Left" Name="textBoxText" VerticalAlignment="Top" Width="280" Text="{Binding CurrentViewModel.PayLoad.CMSSTRUCT_NAME, FallbackValue='loding failed!'}" /></p>
<p>but it seems that the textbox is never updated...? what am i doing wrong?</p>
<p>thanx!</p>
<p></p>
<p></p>
<p> </p>
http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspx#comment7314
rookie07http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspxMon, 19 Dec 2011 16:00:46 GMTRE: Make the TreeView control to be MVVM compliantnice article!
http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspx#comment6196
Bill Ganhttp://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspxWed, 25 May 2011 08:08:10 GMTRE: Make the TreeView control to be MVVM compliantthanks marcos, unfortunately there is not any "official manual" of MVVM since it is a young matter. You have to follow blogs and twits and try it by yourself, and perhaps contributing to the pattern yourself :)
http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspx#comment4810
Andrea Boschinhttp://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspxWed, 03 Nov 2010 10:03:27 GMTRE: Make the TreeView control to be MVVM compliant<p>Hi Andrea ! </p>
<p>I would like to give you congratulations for such a nice article !. I plugged your generic solution into a Silverlight Navigation application so now my app users will be able to navigate to the application's pages through the TreeView navigation system. </p>
<p>Your generic implementation and clean code are amazing ! I'm actually getting used to the MVVM pattern (I come from the Java Swing MVC) could you give me a clue from where I can learn more about MVVM ?</p>
<p>Thank you very much !<br />
--marcos</p>
<p> </p>
<p></p>
http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspx#comment4803
marcoshttp://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspxWed, 03 Nov 2010 02:53:53 GMTRE: Make the TreeView control to be MVVM compliantThat is a nice solution. One thing to think about is if your application uses theming then now the tree control will not be themed since it has been derived from a the base tree control. If you still require theming you can just wire up the events on the treecontrol like normal and then in the events call the commands that are on the view model.
http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspx#comment2874
jsp3536http://www.silverlightshow.net/items/Make-the-TreeView-control-to-be-MVVM-compliant.aspxTue, 05 Jan 2010 19:51:25 GMT