WPF多了一个DataTrigger

时间:2016-02-08 17:44:27

标签: wpf

你知道为什么下面的XAML无效吗?看起来我不能为一个元素提供多个DataTrigger。正如您所知,DataTrigger中的那些Storyboard正在按下按钮执行。 最终的原因是,在按钮单击时,一个网格应向上滑动,另一个向下滑动,实现一种手风琴动画。谢谢

           <StackPanel Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,10,0,0">
                <!--Add New Banner Grid-->
                <!--<Grid DockPanel.Dock="Top" Background="#FFE0FFD2" Height="50">-->
                <Grid x:Name="grdAddBunner">
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Setter Property="Height" Value="50"></Setter>
                            <Setter Property="Background" Value="#FFE0FFD2"></Setter>
                            <Style.Triggers>

                                <DataTrigger Binding="{Binding ElementName=btnEditBunner, Path=IsPressed}" Value="True">
                                    <DataTrigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetProperty="Height" From="150" To="0" Duration="0:0:0.5"></DoubleAnimation>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </DataTrigger.EnterActions>
                                </DataTrigger>

                                <DataTrigger Binding="{Binding ElementName=btnAddBunner, Path=IsPressed}" Value="True">
                                    <DataTrigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="150" Duration="0:0:0.5"></DoubleAnimation>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </DataTrigger.EnterActions>
                                </DataTrigger>

                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Content="Add New Banner" HorizontalAlignment="Center" Foreground="DarkGreen" FontWeight="Bold"></Label>
                        <Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Content="Fund"></Label>
                        <telerik:RadComboBox Grid.Row="1" Grid.Column="1" telerik:StyleManager.Theme="Windows8" Margin="3" ItemsSource="{Binding LstFund}"></telerik:RadComboBox>
                        <Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="Banner"></Label>
                        <TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" telerik:StyleManager.Theme="Windows8" Margin="3" Text="{Binding AddBannerName}"></TextBox>
                        <Button Grid.Row="3" Grid.Column="1" Content="Save" Command="{Binding AddBannerCmd}" Height="25" Width="80" HorizontalAlignment="Left"></Button>
                        <Button Grid.Row="3" Grid.Column="2" Content="Calcel" Height="25" Width="80" HorizontalAlignment="Right"></Button>
                    </Grid>
                </Grid>

                <!--Edit Existing Banner Grid-->
                <!--<Grid DockPanel.Dock="Top" Background="#FFFFF7D2" Height="50">-->
                    <Grid x:Name="grdEditBanner">
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Setter Property="Height" Value="50"></Setter>
                            <Setter Property="Background" Value="#FFFFF7D2"></Setter>
                            <Style.Triggers>
                                

                                <DataTrigger Binding="{Binding ElementName=btnAddBunner, Path=IsPressed}" Value="True">
                                    <DataTrigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetProperty="Height" From="150" To="0" Duration="0:0:0.5"></DoubleAnimation>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </DataTrigger.EnterActions>
                                </DataTrigger>

                                <DataTrigger Binding="{Binding ElementName=btnEditBunner, Path=IsPressed}" Value="True">
                                    <DataTrigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="150" Duration="0:0:0.5"></DoubleAnimation>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </DataTrigger.EnterActions>
                                </DataTrigger>

                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Content="Edit Existing Banner" HorizontalAlignment="Center" Foreground="#FF5B6400" FontWeight="Bold"></Label>
                        <Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Content="Fund"></Label>
                        <telerik:RadComboBox Grid.Row="1" Grid.Column="1" telerik:StyleManager.Theme="Windows8" Margin="3" ItemsSource="{Binding LstFund}" SelectedItem="{Binding SelectedBannerFund}"></telerik:RadComboBox>
                        <Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="Banner"></Label>
                        <TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" telerik:StyleManager.Theme="Windows8" Margin="3" Text="{Binding SelectedBannerName}"></TextBox>
                        <Button Grid.Row="3" Grid.Column="1" Content="Save" Command="{Binding UpdateBannerCmd}" Height="25" Width="80" HorizontalAlignment="Left"></Button>
                        <Button Grid.Row="3" Grid.Column="2" Content="Calcel" Height="25" Width="80" HorizontalAlignment="Right"></Button>
                    </Grid>
                </Grid>
            </StackPanel>

1 个答案:

答案 0 :(得分:1)

“IsPressed”让您知道按钮何时处于“活动状态”,当您释放按钮时,此按钮会再次更改。

您是否尝试将此移动到按钮上的命令绑定并在viewModel上设置这些网格可用于设置样式的属性?