Comments are closed for this post.
Posted by
FallenGameR
@
06 Apr 2009
07:24
There is VSM for WPF:
http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-visual-state-manager-overview.aspxIt is released as a library WPFToolkit on CodePlex. But will be officially included in .NET Framework 4.0.
Posted by
Carlos
@
08 Apr 2009
15:23
Thank you, Thank you, Thank you. I've been struggling with this scenario for days. I just needed for my view elements to not just disappear when the bound viewModel changed or was set to null.
Posted by
Marty
@
09 Apr 2009
00:38
I dont think you actually need the if conditional check in OnContentChanged Method, because either _current or _old contentcontrol should be always non-null, as they are defined in the default style and initialized when the templated parent control is initialized.
Posted by
Josh
@
09 Apr 2009
00:43
@Carlos - you're welcome!
@Marty - unfortunately, OnContentChanged can fire before OnApplyTemplates and you get a nasty exception.
Posted by
Pradeep Mahdevu
@
14 Apr 2009
17:52
Josh,
Even I faced the same problem for some time, The way I resolved is something similar but not the same... But would like your comments...
I manage my animations in code using this line of code.
<inf:ViewModelChangeDispatcher Source="{Binding XXXXAnimation}" SourceChanged="RunAnimation"/>
I defined ViewModelChangeDispatcher as
####################################
I
public class ViewModelChangeDispatcher : FrameworkElement
{
#region Data
public static readonly DependencyProperty SourceProperty;
public static readonly DependencyProperty OnSourceChangedStartStoryboardProperty;
// The routed event
public static RoutedEvent SourceChangedEvent;
#endregion // Data
#region Static Constructor and static methods
static ViewModelChangeDispatcher()
{
SourceProperty = DependencyProperty.Register(
"Source",
typeof(String),
typeof(ViewModelChangeDispatcher),
new FrameworkPropertyMetadata(string.Empty,OnSourcePropertyChanged));
OnSourceChangedStartStoryboardProperty = DependencyProperty.Register(
"OnSourceChangedStartStoryboard",
typeof(Storyboard),
typeof(ViewModelChangeDispatcher));
//Registering the events
SourceChangedEvent = EventManager.RegisterRoutedEvent("SourceChanged",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(ViewModelChangeDispatcher));
}
private static void OnSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ViewModelChangeDispatcher vmcd = d as ViewModelChangeDispatcher;
if (vmcd == null) return;
vmcd.RaiseEvent(new RoutedEventArgs(SourceChangedEvent, vmcd));
if (vmcd.OnSourceChangedStartStoryboard == null) return;
vmcd.OnSourceChangedStartStoryboard.Begin();
}
#endregion
#region constructor and members
public ViewModelChangeDispatcher()
{
this.Visibility = Visibility.Collapsed;
this.Width = 0;
this.Height = 0;
}
/*
* Source is always string.
* It is the onus of the markupextension to convert it to a string.
*
* */
public String Source
{
get { return (String)GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }
}
public event RoutedEventHandler SourceChanged
{
add { AddHandler(SourceChangedEvent, value); }
remove { RemoveHandler(SourceChangedEvent, value); }
}
public Storyboard OnSourceChangedStartStoryboard
{
get { return (Storyboard)GetValue(OnSourceChangedStartStoryboardProperty); }
set { SetValue(OnSourceChangedStartStoryboardProperty, value); }
}
#endregion
}
##############
I could have also written
<inf:ViewModelChangeDispatcher Source="{Binding xxxxxAnimation}"
OnSourceChangedStartStoryboard="addadfa" />
if i had a single animation....
But I pass in an enum to manage all animations.
Posted by
Jones
@
27 Apr 2009
15:20
Nice post...
Posted by
Roboblob
@
10 Jun 2010
08:13
Great post!
I planing to use this approach in my MVVM framework just with Fame element (that inherits ContentControl).
I agree that animations and transitions should definitely be outside of ViewModel and should be controlled via XAML and triggers/events.
Cheers!