Silverlight 触发器在按钮模板中?

发布于 2024-08-24 03:06:06 字数 124 浏览 1 评论 0原文

有谁有关于如何使用 Microsoft.Expression.Interactivity dll 在 Silverlight 按钮模板中使用触发器的功能示例吗?

我想通过触发动画来响应样式中定义的按钮模板中的单击事件。

Does anyone have a functioning example of how to use triggers in a Silverlight Button Template using the Microsoft.Expression.Interactivity dlls?

I want to respond to the click event in a Button's template defined in a style, by triggering an animation.

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

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

发布评论

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

评论(3

青柠芒果 2024-08-31 03:06:06

您想要使用触发 GoToStateActionEventTrigger

<Button x:Name="button" Height="53" HorizontalAlignment="Left" Margin="173,124,0,0" VerticalAlignment="Top" Width="147" Content="Button">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <ic:GoToStateAction TargetName="checkBox" StateName="Checked"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>
<CheckBox x:Name="checkBox" Height="24" HorizontalAlignment="Left" Margin="173,206,0,0" VerticalAlignment="Top" Width="147" Content="CheckBox"/>

要在 Blend 中执行此操作,您需要将 GoToStateAction 拖到按钮上,然后设置 TargetName 属性将 StateName 属性设置为目标 UIElement 并将 StateName 属性设置为所需状态。

You want to use an EventTrigger that fires a GoToStateAction

<Button x:Name="button" Height="53" HorizontalAlignment="Left" Margin="173,124,0,0" VerticalAlignment="Top" Width="147" Content="Button">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <ic:GoToStateAction TargetName="checkBox" StateName="Checked"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>
<CheckBox x:Name="checkBox" Height="24" HorizontalAlignment="Left" Margin="173,206,0,0" VerticalAlignment="Top" Width="147" Content="CheckBox"/>

To do this in Blend you would drag a GoToStateAction onto the button and then set the TargetName property to the target UIElement and the StateName property to the desired state.

南汐寒笙箫 2024-08-31 03:06:06

您始终可以使用 VisualStateManager 并通过处理 Button 的单击事件来更改为“单击”状态。

void myButton_Click(object sender, RoutedEventArgs)
{
     VisualStateManager.GoToState(this, "Click", true);
}

您还需要在 XAML 代码中定义样式和状态。

<Style x:Key="ButtonStyle" TargetType="Button">       
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="StateGroup">
                               <VisualState x:Name="ActiveLink">
                                    <Storyboard>
                                        //animations go here
                              ...

另外,请记住 Button 对象有许多预定义状态,例如“禁用”、“按下”(单击?)、“鼠标悬停”和“正常”。

You can always use the VisualStateManager and change to the "Click" state by handling the click event of a Button.

void myButton_Click(object sender, RoutedEventArgs)
{
     VisualStateManager.GoToState(this, "Click", true);
}

You will also need to define a style and state in the XAML code.

<Style x:Key="ButtonStyle" TargetType="Button">       
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="StateGroup">
                               <VisualState x:Name="ActiveLink">
                                    <Storyboard>
                                        //animations go here
                              ...

Also, remember that Button objects have a bunch of predefine states like Disabled, Pressed (Click?), MouseOver, and Normal.

旧时浪漫 2024-08-31 03:06:06

看起来当时是不可能的。

looks like it wasn't possible at that time.

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