The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Visual State Binding to ViewModel in Windows 10 RRS feed

  • Question

  • Hello,

    I have a page with three VisualState Groups. I need to control one group from the ViewModel. I have used a DependencyProperty in another App with only one VisualState Group. This doesn't work in this case (Windows 10 UWP, 3 Groups). Does anyone have an idea how make this working?

    public class VisualStateHelper : DependencyObject, IBehavior
        {
            public DependencyObject AssociatedObject { get; private set; }
    
            public object Value
            {
                get { return (Enum)GetValue(ValueProperty); }
                set { SetValue(ValueProperty, value); }
            }
    
            public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
                "Value",
                typeof(object),
                typeof(VisualStateHelper), 
                new PropertyMetadata(null, ValuePropertyChanged));
    
            private static void ValuePropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
                var behavior = sender as VisualStateHelper;
                if (behavior.AssociatedObject == null || e.NewValue == null) return;
    
                VisualStateManager.GoToState(behavior.AssociatedObject as Control, e.NewValue.ToString(), true);
            }
    
            public void Attach(DependencyObject associatedObject)
            {
                var control = associatedObject as Control;
                if (control == null) throw new ArgumentException("VisualStateHelper can be attached only to Control");
    
                AssociatedObject = associatedObject;
            }
    
            public void Detach()
            {
                AssociatedObject = null;
            }
        }

    Saturday, February 6, 2016 10:20 PM

All replies

  • In what way doesn't it work? What does your xaml look like?

    http://pauliom.wordpress.com

    Sunday, February 7, 2016 9:13 AM
  • <Interactivity:Interaction.Behaviors>
            <dependencies:VisualStateDependencyProperty VisualStateProperty="{Binding State}"/>
        </Interactivity:Interaction.Behaviors>

    Thats how it is impemented in XAML.

    I think because of multiple VisualState Groups it has no idea to which it belongs.

    At the Moment, as a Workaround I am using command binding to inform the viewmodel about the visual state.

    But on another page, using command binding as well, I Need to execute an async command with Parameter where I am still looking for a solution. Template10 has an async command, but without Parameter acceptance.

    Thursday, February 11, 2016 2:14 PM
  • Hello,

    >>But on another page, using command binding as well, I Need to execute an async command with Parameter where I am still looking for a solution. Template10 has an async command, but without Parameter acceptance.

    It seems that you have solved this problem by yourself in this thread:
    https://social.msdn.microsoft.com/Forums/de-DE/196d7240-0fcc-421e-a452-bca169b77971/delegatecommandobject-is-not-beeing-invoked?forum=wpdevelop .

    If you have any others question, welcome to post it in this forum.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 23, 2016 8:03 AM