帮我为 Expander 类型的控件设置事件触发器!

发布于 2024-10-16 17:34:02 字数 1816 浏览 4 评论 0原文

你好,我正在尝试做这样的事情

  allrooms = remote.GetAllRooms();
        for (int a = 0; a < allrooms.Count; a++) {
            Expander ex = new Expander();
            ex.Expanded += expander1_Expanded;
            ex.Width = 254;
            ex.Name = ("expander" + a);
            ex.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            ex.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            ex.Header = allrooms[a].nome;
            WrapPanel panel = new WrapPanel();
            panel.Opacity = 1;
            panel.Width = 254;
            for (int b = 0; b < allusers.Count; b++) {
                System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
                lbl.Content = allusers[b].nick;
                lbl.Width = 127;
                panel.Children.Add(lbl);
            }
            ex.Content = panel;
            Canvas.SetTop(ex, (30 * a));
            canvasleft.Children.Add(ex);
        }
        myTimer.Stop();

现在我的目标是将此事件触发器添加到在 xaml 或 c# 中创建的扩展器中。

    <Canvas.Triggers>
        <EventTrigger RoutedEvent="Expander.Expanded" SourceName="expander">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="listBox" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Canvas.Triggers>

类似的东西,但有错误,我需要的是类似 x:Type Expander 的东西,用于画布中所有创建的扩展器。

有人可以帮助我吗?

Hello im trying to do something like this

  allrooms = remote.GetAllRooms();
        for (int a = 0; a < allrooms.Count; a++) {
            Expander ex = new Expander();
            ex.Expanded += expander1_Expanded;
            ex.Width = 254;
            ex.Name = ("expander" + a);
            ex.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            ex.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            ex.Header = allrooms[a].nome;
            WrapPanel panel = new WrapPanel();
            panel.Opacity = 1;
            panel.Width = 254;
            for (int b = 0; b < allusers.Count; b++) {
                System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
                lbl.Content = allusers[b].nick;
                lbl.Width = 127;
                panel.Children.Add(lbl);
            }
            ex.Content = panel;
            Canvas.SetTop(ex, (30 * a));
            canvasleft.Children.Add(ex);
        }
        myTimer.Stop();

And now my objective is to add this event trigger to that Expanders created, in xaml or c#.

    <Canvas.Triggers>
        <EventTrigger RoutedEvent="Expander.Expanded" SourceName="expander">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="listBox" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Canvas.Triggers>

Something like that but that have errors and what i need is something like x:Type Expander for all created expanders in the canvas.

Can anybody help me?

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

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

发布评论

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

评论(1

方圜几里 2024-10-23 17:34:02

尝试如下操作:

<Canvas.Resources>
    <Style TargetType="Expander">
        <Style.Triggers>
        <EventTrigger RoutedEvent="Expander.Expanded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="listBox" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
        </Style.Triggers>
    </Style>
</Canvas.Resources>

如果放置在资源中,则由于 TargetType,样式应应用于所有 Expander

Try something like:

<Canvas.Resources>
    <Style TargetType="Expander">
        <Style.Triggers>
        <EventTrigger RoutedEvent="Expander.Expanded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="listBox" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
        </Style.Triggers>
    </Style>
</Canvas.Resources>

If placed in the resources the style should be applied to all Expanders because of the TargetType.

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