I using Expression Blend for getting an animation though the change of states. When i hit a button the animation starts. And it works!!!!
But... The problem is that if i navigate thought another user control and get back to the one who wish to animate, when i hit the button to start the animation it keeps showing me the exception 'gridMain' grid name cannot be found in the name scope of 'System.Windows.Controls.Grid'.
Code:
<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>
I'm using MVVM and changing user controls by defining a property in the MainViewModel:
And the 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>
It seens like the problem is in the navigation on the windows. When i navigate thought another window when it loads he gets "confused"... But i don't know who to solve it.
Can anybody help me please?
Thanks,