在DataTemplate中调用Storyboard

时间:2013-10-22 15:41:48

标签: c# xaml mvvm

我的代码中出现了一个常常错误,我可以解决。

  

没有适用的名称范围来解析名称'gridCallLog'。

<DataTemplate x:Key="ContentDetail">
        <DataTemplate.Resources>
            <Storyboard x:Key="StoryCallLogOn">
                <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="gridCallLog">
                    <EasingThicknessKeyFrame KeyTime="0" Value="0,0,10,23.04"/>
                    <EasingThicknessKeyFrame KeyTime="0:0:0.6" Value="0,0,10,200"/>
                </ThicknessAnimationUsingKeyFrames>
                <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="borderCallLog">
                    <EasingThicknessKeyFrame KeyTime="0" Value="0,402,10,23.04"/>
                    <EasingThicknessKeyFrame KeyTime="0:0:0.6" Value="0,225,10,23.04"/>
                </ThicknessAnimationUsingKeyFrames>
            </Storyboard>
        </DataTemplate.Resources>
        <StackPanel  Orientation="Horizontal" Height="500" >
            <Border Margin="10,5,0,10" BorderBrush="Transparent" CornerRadius="3" BorderThickness="1" Width="1050">
                <StackPanel Margin="5,5,9,5" Orientation="Horizontal">
                    <dx:DXTabControl Width="850" Margin="5,5,0,0">
                        <dx:DXTabItem Header="Call Log">
                            <StackPanel>
                                <dxg:GridControl x:Name="gridCallLog" Height="400" ItemsSource="{Binding ElementName=MainStack,Path=DataContext.CallLog}"  
                                dx:ThemeManager.ThemeName="Office2010Blue" Margin="0,0,10,0" SelectedItem="{Binding ElementName=MainStack,Path=DataContext.SelectedCallLog,UpdateSourceTrigger=PropertyChanged}" >
                                    <dxg:GridControl.Columns >


<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
    <command:EventToCommand Command="{Binding ElementName=MainStack,Path=DataContext.CallLogOnCommand}" />
</i:EventTrigger>
<ei:DataTrigger Binding="{Binding ElementName=MainStack,Path=DataContext.CallLogOn, Mode=OneWay}" Value="ON">
    <ei:ControlStoryboardAction Storyboard="{StaticResource StoryCallLogOn}" ControlStoryboardOption="Play"/>
</ei:DataTrigger>

故事板被调用没有问题。但由于某种原因,即使故事板在DataTemplate.Resources中,它也看不到名为gridCallLog的GridControl。 任何指针都会被感激地接受。斯科特

1 个答案:

答案 0 :(得分:3)

您应该将资源添加到DataTemplate内的控件之一,而不是DataTemplate本身:

<DataTemplate x:Key="ContentDetail">
        <StackPanel Orientation="Horizontal" Height="500" >
        <StackPanel.Resources>
            <Storyboard x:Key="StoryCallLogOn">
                <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="gridCallLog">
                    <EasingThicknessKeyFrame KeyTime="0" Value="0,0,10,23.04"/>
                    <EasingThicknessKeyFrame KeyTime="0:0:0.6" Value="0,0,10,200"/>
                </ThicknessAnimationUsingKeyFrames>
                <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="borderCallLog">
                    <EasingThicknessKeyFrame KeyTime="0" Value="0,402,10,23.04"/>
                    <EasingThicknessKeyFrame KeyTime="0:0:0.6" Value="0,225,10,23.04"/>
                </ThicknessAnimationUsingKeyFrames>
            </Storyboard>
        </StackPanel.Resources>
        <Border Margin="10,5,0,10" BorderBrush="Transparent" CornerRadius="3" BorderThickness="1" Width="1050">
            <StackPanel Margin="5,5,9,5" Orientation="Horizontal">
                <dx:DXTabControl Width="850" Margin="5,5,0,0">
                    <dx:DXTabItem Header="Call Log">
                        <StackPanel>
                            <dxg:GridControl x:Name="gridCallLog" Height="400" ItemsSource="{Binding ElementName=MainStack,Path=DataContext.CallLog}"  
                            dx:ThemeManager.ThemeName="Office2010Blue" Margin="0,0,10,0" SelectedItem="{Binding ElementName=MainStack,Path=DataContext.SelectedCallLog,UpdateSourceTrigger=PropertyChanged}" >
                                <dxg:GridControl.Columns >