我使用Expression Blend通过状态的变化来获取动画。 当我点击按钮时动画开始。它有效!!!!
但是......问题是,如果我导航想到另一个用户控件并回到想要设置动画的人,当我按下按钮开始动画时它会一直显示异常' gridMain&# 39;无法在System.Windows.Controls.Grid'的名称范围内找到网格名称。
代码:
<Grid x:Name="grid1" HorizontalAlignment="Left" Height="314.5" VerticalAlignment="Top" Width="234.5" RenderTransformOrigin="0.5,0.5">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="Animations">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Options">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="gridMain">
<EasingDoubleKeyFrame KeyTime="0" Value="196.5"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Grid x:Name="grid2" HorizontalAlignment="Left" Height="314.5" VerticalAlignment="Top" Width="234.5" Background="#FF818181" IsEnabled="{Binding CurrentViewModel.IsShowingOptions}">
<xctk:WatermarkTextBox x:Name="textBoxPurchaseOrder" Margin="10,65.988,0,0" TextWrapping="Wrap" Text="{Binding CurrentViewModel.PurchaseOrderNo, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" Watermark="Pedido de Compra" VerticalAlignment="Top" HorizontalAlignment="Left" Width="122" local:FocusExtension.IsFocused="{Binding CurrentViewModel.PurchaseOrderFocus}" Style="{DynamicResource TextBoxTemplate}">
<xctk:WatermarkTextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding CurrentViewModel.FindCommand}" />
</xctk:WatermarkTextBox.InputBindings>
</xctk:WatermarkTextBox>
<xctk:WatermarkTextBox x:Name="textBoxEanMaterial" HorizontalAlignment="Left" Margin="10,102.988,0,0" TextWrapping="Wrap" Text="{Binding CurrentViewModel.EAN, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="122" Watermark="EAN" Background="White" Style="{DynamicResource TextBoxTemplate}" >
<xctk:WatermarkTextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding CurrentViewModel.FindCommand}" />
</xctk:WatermarkTextBox.InputBindings>
</xctk:WatermarkTextBox>
<Button x:Name="buttonExit" Content="Saír" HorizontalAlignment="Left" Margin="10,265.54,0,0" VerticalAlignment="Top" Width="75" Height="38.96" Command="{Binding CurrentViewModel.ExitCommand}"/>
<Button Content="Button" Margin="141.309,72.488,50.321,199.476" Style="{DynamicResource ButtonStyleFind}" Command="{Binding CurrentViewModel.FindCommand}"/>
<Button Content="Button" Height="42.536" Margin="10,10,181.63,261.964" Style="{DynamicResource ButtonStyleHome}" Width="42.87" Command="{Binding CurrentViewModel.GoHomeCommand}"/>
<Image Margin="146,240,40.5,26.5" Source="/SGAMobile;component/Resources/Button-Cross-blue-48.png" Stretch="Fill"/>
</Grid>
<Grid x:Name="gridMain" RenderTransformOrigin="0.5,0.5" Background="#FFFBFBFB" d:IsEffectDisabled="True">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Height="34.96" VerticalAlignment="Top">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="#FFD8D8D8" Offset="0"/>
<GradientStop Color="#6CEAEAEA" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Button Content="Button" Margin="1.728,2.272,202.771,2.687" Style="{DynamicResource ButtonOptions}" Command="{Binding CurrentViewModel.ShowOptionsCommand}" Width="30" Height="30"/>
<Label Content="{Binding CurrentViewModel.ViewName}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
<Path Data="M302,79 L600.42922,79" Fill="Red" HorizontalAlignment="Left" Height="5.5" Margin="0,34.167,0,-4.707" Stretch="Fill" Stroke="#FF979797" VerticalAlignment="Top" Width="234.5"/>
</Grid>
<ListView Width="234.5" Margin="0,34.96,0,52.333" ItemsSource="{Binding CurrentViewModel.PurchaseOrders}" ItemTemplate="{DynamicResource ListViewPOItemTemplate}" HorizontalAlignment="Left" BorderBrush="{x:Null}" SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectedItem="{Binding CurrentViewModel.SelectedItem}" Background="{x:Null}" Style="{DynamicResource ListViewTemplate}"/>
<Button x:Name="buttonNext_Copy" Content="Voltar" HorizontalAlignment="Left" Margin="0,262.167,0,0" VerticalAlignment="Top" Width="117.25" Height="28" Command="{Binding CurrentViewModel.GoHomeCommand}" BorderBrush="#FFB0B0B0" Background="#FF03AEDA" Foreground="White" BorderThickness="0,0,1,0" Style="{DynamicResource ButtonPopupStyle}"/>
<Button x:Name="buttonNext" Content="Seguinte" HorizontalAlignment="Left" Margin="117.125,262.167,0,0" VerticalAlignment="Top" Width="117.375" Height="28" Command="{Binding CurrentViewModel.GoNext}" Foreground="White" BorderThickness="1,0,0,0" BorderBrush="#FFB0B0B0" Background="#FF03AEDA" Style="{DynamicResource ButtonPopupStyle}"/>
<Grid x:Name="grid3" Background="#33000000" Visibility="{Binding CurrentViewModel.IsLoading}" d:IsHidden="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown" SourceName="grid3" SourceObject="{Binding ElementName=grid3}">
<Custom:EventToCommand Command="{Binding CurrentViewModel.ShowOptionsCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Image x:Name="image" Margin="91,120,101.5,152.5" Source="/SGAMobile;component/Resources/Metro-Loading-Blue-64.png" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" Height="42" Width="42" RenderTransformOrigin="0.5,0.5" Grid.Column="1">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Grid>
<Grid HorizontalAlignment="Left" Height="24.333" Margin="-0.125,290.167,0,0" VerticalAlignment="Top" Width="234.625">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="93*"/>
<ColumnDefinition Width="142*"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding CurrentViewModel.Message}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="234.625" Foreground="{Binding CurrentViewModel.MessageColor}" FontSize="10.667" FontWeight="Bold" Grid.ColumnSpan="2"/>
</Grid>
</Grid>
我使用MVVM并通过在MainViewModel中定义属性来更改用户控件:
public ViewModelBase CurrentViewModel
和App.xaml
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
<DataTemplate DataType="{x:Type vm:EntryViewModel}">
<views:EntryView />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:GoodsReceiptViewModel}">
<views:GoodsReceiptView />
</DataTemplate>
任何想法?
谢谢,
答案 0 :(得分:0)
每次触发故事板时都会评估故事板TargetName,该故事板与目标对象是异步的。尝试使用Target = {Binding ElementName = targetName}来保存绑定。 Name cannot be found in the name scope of 'System.Windows.Controls.Button'