WPF 中 ItemsControl 内的缩放按钮

发布于 2024-12-09 18:44:12 字数 3436 浏览 0 评论 0原文

我创建了包含按钮的 ItemsControl。想要制作缩放按钮。一切都是在 Blend 4 中创建的,所以我很惊讶这在运行后不起作用。不知道出了什么问题。

    <ItemsControl Grid.Row="1" ItemsSource="{Binding Symbols}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <DataTemplate.Resources>
                    <Storyboard x:Key="OnClick1">
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="button">
                            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="2"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="button">
                            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="2"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </DataTemplate.Resources>
                <Button x:Name="button" cal:Message.Attach="[Event MouseDoubleClick] = [Action SymbolButton($dataContext)]" RenderTransformOrigin="0.5,0.5">
                    <Button.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Button.RenderTransform>
                    <Button.Template>
                        <ControlTemplate>
                            <Label FontFamily="{Binding ElementName=cbLetterTypes, Path=EditValue.Name,  Mode=OneWay}" Height="50" Width="50"  Content="{Binding Value, Mode=OneWay}" ToolTip="{Binding ToolTip}" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="1" BorderBrush="Black" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"></Label>
                        </ControlTemplate>
                    </Button.Template>                        
                </Button>
                <DataTemplate.Triggers>
                    <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
                        <BeginStoryboard x:Name="OnClick1_BeginStoryboard" Storyboard="{StaticResource OnClick1}"/>
                        <StopStoryboard BeginStoryboardName="OnClick1_BeginStoryboard"/>
                    </EventTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                    <WrapPanel/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.Template>
            <ControlTemplate>
                <ScrollViewer Margin="5" VerticalScrollBarVisibility="Auto">
                    <ItemsPresenter/>
                </ScrollViewer>
            </ControlTemplate>
        </ItemsControl.Template>
    </ItemsControl>

I created ItemsControl containg buttons. Want to make Scale clicked button. Everything was created in Blend 4 so I'm surprised that this is not working after running. Have no idea what's the problem.

    <ItemsControl Grid.Row="1" ItemsSource="{Binding Symbols}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <DataTemplate.Resources>
                    <Storyboard x:Key="OnClick1">
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="button">
                            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="2"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="button">
                            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="2"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </DataTemplate.Resources>
                <Button x:Name="button" cal:Message.Attach="[Event MouseDoubleClick] = [Action SymbolButton($dataContext)]" RenderTransformOrigin="0.5,0.5">
                    <Button.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Button.RenderTransform>
                    <Button.Template>
                        <ControlTemplate>
                            <Label FontFamily="{Binding ElementName=cbLetterTypes, Path=EditValue.Name,  Mode=OneWay}" Height="50" Width="50"  Content="{Binding Value, Mode=OneWay}" ToolTip="{Binding ToolTip}" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="1" BorderBrush="Black" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"></Label>
                        </ControlTemplate>
                    </Button.Template>                        
                </Button>
                <DataTemplate.Triggers>
                    <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
                        <BeginStoryboard x:Name="OnClick1_BeginStoryboard" Storyboard="{StaticResource OnClick1}"/>
                        <StopStoryboard BeginStoryboardName="OnClick1_BeginStoryboard"/>
                    </EventTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                    <WrapPanel/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.Template>
            <ControlTemplate>
                <ScrollViewer Margin="5" VerticalScrollBarVisibility="Auto">
                    <ItemsPresenter/>
                </ScrollViewer>
            </ControlTemplate>
        </ItemsControl.Template>
    </ItemsControl>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迎风吟唱 2024-12-16 18:44:12
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
    <BeginStoryboard x:Name="OnClick1_BeginStoryboard" Storyboard="{StaticResource OnClick1}"/>
    <StopStoryboard BeginStoryboardName="OnClick1_BeginStoryboard"/>
</EventTrigger>

你启动故事板并立即停止,这应该如何进行?

<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
    <BeginStoryboard x:Name="OnClick1_BeginStoryboard" Storyboard="{StaticResource OnClick1}"/>
    <StopStoryboard BeginStoryboardName="OnClick1_BeginStoryboard"/>
</EventTrigger>

You start the storyboard and stop it right away, how is that supposed to work out?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文