帮我为 Expander 类型的控件设置事件触发器!
你好,我正在尝试做这样的事情
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试如下操作:
如果放置在资源中,则由于
TargetType
,样式应应用于所有Expander
。Try something like:
If placed in the resources the style should be applied to all
Expanders
because of theTargetType
.