更改视图并获取:在"System.Windows.Controls.Grid"的名称范围内找不到网格名称



I使用Expression Blend通过状态的更改来获取动画。当我按下一个按钮,动画就开始了。它起作用了!!!!

但是。。。问题是,如果我浏览到另一个用户控件并返回到希望动画的用户控件,当我点击按钮开始动画时,它会一直向我显示异常"gridMain"网格名称在"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>

有什么想法吗?

谢谢,

每次触发情节提要时,都会评估情节提要TargetName,它与目标对象异步。请尝试改用Target={Binding ElementName=targetName},这样可以保存绑定。在';的名称范围中找不到名称;System.Windows.Controls.Button';

相关内容

最新更新