开发者

Help me put event trigger for controls of type Expander!

开发者 https://www.devze.com 2023-02-09 20:50 出处:网络
Hello im trying to do something like this allrooms = remote.GetAllRooms(); for (int a = 0; a < allrooms.Count; a++) {

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消