我有一个ToggleButton
打开一个弹出窗口,并有一个ItemsControl
Popup
。DataTemplate中的故事板
我想在项目控件中点击物品时隐藏弹出窗口。
<ToggleButton Content="?????" x:Name="LeaveButton" Style="{StaticResource ToggleButtonImageStyle}" Padding="13"/>
<Popup
KeyDown="UIElement_OnKeyDown"
Opened="SubMenuPopup_OnOpened"
IsOpen="{Binding IsChecked, ElementName=LeaveButton}"
StaysOpen="False"
x:Name="LeavePopup"
AllowsTransparency="True"
PopupAnimation="Fade"
PlacementTarget="{Binding ElementName=LeaveButton}"
Placement="Right">
<StackPanel Orientation="Horizontal" Margin="15">
<Polygon Points="15 15,0 30,15 45" Fill="{DynamicResource HeaderBackgroundBrush}" />
<StackPanel Width="250">
<ItemsControl ItemsSource="{Binding WorkshopList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button
Content="{Binding Name}"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.LeaveCommand}"
CommandParameter="{Binding Id}"
Style="{StaticResource ButtonImageTextStyle}"
Padding="20">
<Button.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click">
<BeginStoryboard Storyboard="{StaticResource HideLeavePopup}" />
</EventTrigger>
</Button.Triggers>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</Popup>
并为此设置了一个故事。
<Storyboard x:Key="HideLeavePopup" Storyboard.TargetName="LeaveButton" Storyboard.TargetProperty="IsOpen">
<BooleanAnimationUsingKeyFrames>
<DiscreteBooleanKeyFrame KeyTime="00:00:00.1" Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
,但是当我用这个,我得到以下错误
LeaveButton name can not be found in the name scope of type 'System.Windows.Control.Button'
除此之外,我认为你的做法是不是一个好(我发现了自己不久前)。属性动画的问题在于它没有真正设置属性值,而是覆盖了有效值。结果有两种情况是可能的:如果动画的FillBehavior设置为HoldEnd,动画将阻止弹出窗口重新打开(IsOpen有效值将保持为false),否则(如果设置为Stop ')有效的“IsOpen”值将恢复为“true”,导致弹出窗口在动画结束后重新打开。 – Grx70