我有一个按钮,它应该是一个包含多个子项的菜单。菜单应该“向下滑动”或类似的东西。我正在尝试使用简单的 TranslateTransform 来完成此操作,但我不断收到以下运行时错误:System.InvalidOperationException: 'translateTransform' name cannot be found in the name scope of 'System.Windows.Controls.ContextMenu'.
原因是什么?有没有办法解决这个问题?菜单动画方法是否有任何(免费)替代方案?
<Button Name="Settings" Margin="2" Style="{StaticResource GrayGrayButtonStyle}">
<Image Source="gear.png" />
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Item 0"/>
<MenuItem Header="Item 1"/>
<MenuItem Header="Item 2"/>
<MenuItem Header="Item 3"/>
<ContextMenu.RenderTransform>
<TranslateTransform x:Name="translateTransform"
X="{Binding
Path=ActualWidth,
RelativeSource={RelativeSource
FindAncestor,
AncestorType={x:Type Button}}}" />
</ContextMenu.RenderTransform>
<ContextMenu.Triggers>
<EventTrigger RoutedEvent="ContextMenu.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="translateTransform"
Storyboard.TargetProperty="(TranslateTransform.X)"
To="0"
BeginTime="0:0:3.5"
AutoReverse="False"
Duration="0:0:2.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</ContextMenu.Triggers>
</ContextMenu>
</Button.ContextMenu>
</Button>