Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I change the VisualState in a View from the ViewModel?
    primarykey
    data
    text
    <p>I'm new to WPF and MVVM. I think this is a simple question. My ViewModel is performing an asynch call to obtain data for a DataGrid which is bound to an ObservableCollection in the ViewModel. When the data is loaded, I set the proper ViewModel property and the DataGrid displays the data with no problem. However, I want to introduce a visual cue for the user that the data is loading. So, using Blend, I added this to my markup:</p> <pre><code> &lt;VisualStateManager.VisualStateGroups&gt; &lt;VisualStateGroup x:Name="LoadingStateGroup"&gt; &lt;VisualState x:Name="HistoryLoading"&gt; &lt;Storyboard&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="HistoryGrid"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;VisualState x:Name="HistoryLoaded"&gt; &lt;Storyboard&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="WorkingStackPanel"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; </code></pre> <p>I <em>think</em> I know how to change the state in my code-behind (something similar to this): </p> <pre><code>VisualStateManager.GoToElementState(LayoutRoot, "HistoryLoaded", true); </code></pre> <p>However, the place where I want to do this is in the I/O completion method of my ViewModel which does not have a reference to it's corresponding View. How would I accomplish this using the MVVM pattern?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload