В универсальных приложениях (архитектура MVVM) мой визуальный код состояния не работает для видимости макета (с индикатором прогресса). Пожалуйста, сообщите мне, где я ошибся.VisualState не работает для видимости макета
И я следовал этому Link
В VisualState в XAML:
<Page
x:Class="Carrot_Windows.CarrotLoginPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Carrot_Windows"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
DataContext="{Binding Login, Mode=TwoWay, Source={StaticResource Locator}}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="Progress_layout">
<VisualState x:Name="BaseState">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ProgressGrid">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ProgressState">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ProgressGrid">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<i:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding CurrentState}"
ComparisonCondition="Equal" Value="BaseState">
<core:GoToStateAction StateName="BaseState" />
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding CurrentState}"
ComparisonCondition="Equal" Value="ProgressState">
<core:GoToStateAction StateName="ProgressState" />
</core:DataTriggerBehavior>
</i:Interaction.Behaviors>
Мастер компоновки
<Grid x:Name="Grid_Master" Background="White">
// THE LAYOUT ON WHICH VISUAL STATE APPLIED
<Grid x:Name="ProgressGrid" Background="Black" Opacity=".7" Grid.RowSpan="5" Grid.ColumnSpan="3" Canvas.ZIndex="1" >
<ProgressRing Height="90" Width="90" HorizontalAlignment="Center" VerticalAlignment="Center" IsActive="True" />
</Grid>
<Viewbox Grid.Column="1" Grid.Row="3" >
<Border Background="LightGray" Width="520" Height="300" >
<Grid>
//Do something
</Grid>
</Border>
</Viewbox>
</Grid>
C# код на ViewModel:
private enum ViewModelState
{
BaseState,
ProgressState
}
private string currentState;
public string CurrentState
{
get { return currentState; }
set
{
this.Set(ref currentState, value);
RaisePropertyChanged("CurrentState");
}
}
private void LoginButtonClicked()
{
CurrentState = ViewModelState.ProgressState.ToString();
}
Я думаю, что есть проблема в Value = "ProgressGrid"> Это не называется ProgressState? –
@juan Pablo Garcio Coello да, спасибо, но визуальное состояние BaseState также не срабатывает. –
Где в XAML вы добавили VisualState и поведение, ниже? –