这有点奇怪。 我正在寻找使用XAML获取扩展器(或任何具有已检查和未检查状态的东西,如Togglebutton等),以便在被“忽略”后将自身设置为折叠/未选中(对于在一段时间后,缺乏一个更好的术语。
目前我正在使用的参数来决定它是否被“忽略” MouseOver = False 和 IsExpanded = True ,当此触发器被引发时,它将开始一个故事板,在大约3秒后将“IsExpanded”设置为“False”。
哪种工作正常。
问题是当你想要重新扩展扩展器时 - 你不能,因为故事板似乎持有它为False。
我可能只是在做一些愚蠢的事情/不考虑某种角度,但这令人非常沮丧。 如果事实证明单独使用XAML无法做到那就没关系,但我更喜欢纯粹的XAML解决方案如果存在。
为了更好地说明问题,我已经制作了一个可以下载的示例项目,可以下载Here.
或者,这是要查看的代码:
<Window.Resources>
<Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
<Style.Resources>
<Storyboard x:Key="ExpanderSelfCollapseStoryboard">
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="{x:Null}" Storyboard.TargetProperty="(Expander.IsExpanded)">
<DiscreteBooleanKeyFrame KeyTime="0:0:3" Value="False" />
</BooleanAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Tag)" Storyboard.TargetName="{x:Null}">
<DiscreteObjectKeyFrame KeyTime="0" Value="Not long..."/>
<DiscreteObjectKeyFrame KeyTime="0:0:3" Value="Notice you can't open the expander anymore :("/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</Style.Resources>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.EnterActions>
<BeginStoryboard x:Name="ExpanderSelfCollapseStoryboard_BeginStoryboard" Storyboard="{StaticResource ExpanderSelfCollapseStoryboard}" />
</MultiTrigger.EnterActions>
<MultiTrigger.Conditions>
<Condition Property="IsExpanded" Value="True" />
<Condition Property="IsMouseOver" Value="False" />
</MultiTrigger.Conditions>
</MultiTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Expander x:Name="localExpander"
Background="DodgerBlue"
Header="Expand me!"
Style="{StaticResource ExpanderStyle}"
Tag="Up there!">
<Border Height="200"
Margin="5"
Background="Orange">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
FontWeight="Bold"
Foreground="White"
Text="Now move your mouse over the whitespace for a few seconds please."
TextAlignment="Center"
TextWrapping="Wrap" />
</Border>
</Expander>
<TextBlock Grid.Row="1"
VerticalAlignment="Center"
FontSize="22"
Foreground="LightGray"
Text="{Binding ElementName=localExpander,
Path=Tag}"
TextAlignment="Center" />
</Grid>
我会感谢任何人可以提供的任何帮助或建议。
谢谢,
- 洛根