DataTrigger和Storyboard出了点问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DataTrigger和Storyboard出了点问题相关的知识,希望对你有一定的参考价值。

我一直试图让它工作4天,请帮助我。

我有一个故事板,一切都很好,直到我需要将触发操作从按钮单击更改为Binding on boolean变量。它全部写在模板中,我想这会使任务变得更复杂。代码是(它仍然有效):

    <Border x:Name="panelControl" Grid.RowSpan="4" Margin="0,0,-450,0" VerticalAlignment="Stretch" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" Width="450" Height="275" DataContext="{Binding CurrentPanelViewModel}" >
            <Border.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Border.RenderTransform>

                <Canvas Background="#FFC6E8E6">
                    ...
                </Canvas>
            </Grid>
        </Border>

    <Grid.Triggers>
            <EventTrigger RoutedEvent="Button.Click" SourceName="AddButton2">
                <BeginStoryboard Name="StartStoryboard">
                    <Storyboard SpeedRatio="12" TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                        <DoubleAnimation 
                            Storyboard.TargetName="panelControl" 
                            Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
                            Duration="0:0:005" From="0" To="-700" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>

现在我写了。

<Border x:Name="panelControl" Grid.RowSpan="4" Margin="0,0,-450,0" VerticalAlignment="Stretch" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" Width="450" Height="275" DataContext="{Binding Path=Controller.LegViewModel.CurrentPanelViewModel}" >
            <Border.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Border.RenderTransform>

            <Grid.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path = PanelOpened}">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard >
                                        <Storyboard SpeedRatio="12" TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                                            <DoubleAnimation
                                                Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
                                                Duration="0:0:005" From="0" To="-700" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.EnterActions>

                                <!--<DataTrigger.ExitActions>
                                     you could animate close too if you wanted 
                                </DataTrigger.ExitActions>-->
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>

                <Canvas Background="#FFC6E8E6">
                    ....
                </Canvas>
            </Grid>
        </Border>

没有任何反应。尽管事实上我检查了PanelOpened通知。

---------- ----------- UPDATE

我在DataTrigger中添加了Value =“True”,现在我的OnPropertyChanged出错了(当propertyName = PanelOpened时):

public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        //если PropertyChanged не нулевое - оно будет разбужено
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public bool PanelOpened
    {
        get { return _panelOpened; }
        set
        {
            _panelOpened = value;
            OnPropertyChanged();
        }
    }

error:System.InvalidOperationException:''[Unknown]'属性不指向路径'(0)中的DependencyObject。(1)[3]。(2)'。'

答案

当绑定中的值等于您指定的某个值时,将触发数据触发器。但是你没有指定价值。如果你希望当PanelOpened的值变为true时触发器“触发”,请说:

<DataTrigger Binding="{Binding PanelOpened}" Value="True">
另一答案

问题是我试图将DataTrigger添加到网格样式而不是边框​​。工作版本:

            <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path = PanelOpened}" Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard >
                                    <Storyboard SpeedRatio="12" TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                                        <DoubleAnimation
                                            Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
                                            Duration="0:0:005" From="0" To="-700" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>

以上是关于DataTrigger和Storyboard出了点问题的主要内容,如果未能解决你的问题,请参考以下文章

出了点问题,请从 BotFramework MessagingExtesion 重试

条纹结帐:出了点问题

出了点错,待改正

404 Not Found:出了点问题[重复]

Asm 程序...出了点问题

出了点问题;缺少所有 ROC 指标值: