2
<Style x:Key="FavouriteMenuItemStyle" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource BasicFavouriteItemStyle}">
<Setter Property="Width" Value="Auto"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Grid>
<ToggleButton x:Name="Bd"
Content="{Binding Header}"
Style="{StaticResource FolderButtonStyle}"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}"
Margin="{TemplateBinding Margin}"
Padding="{TemplateBinding Padding}"
Focusable="False"/>
<Popup x:Name="PopupMenu"
IsOpen="False"
Placement="Bottom"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
AllowsTransparency="True"
Focusable="False"
StaysOpen="False">
<Border BorderBrush="{StaticResource MpButtonNormalStrokeBrush}"
Background="{StaticResource MpButtonNormalFillBrush}"
BorderThickness="1"
CornerRadius="3"
Padding="4">
<ItemsControl ItemsSource="{Binding Favourites}" ItemTemplate="{StaticResource FavouriteMenuItemDataTemplate}"/>
</Border>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" SourceName="Bd" Value="True">
<Setter Property="IsOpen" TargetName="PopupMenu" Value="True"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我定義了以下樣式。我想將Popup的IsOpen
屬性綁定到ToggleButton的IsChecked
屬性。模板中控件之間的綁定
我正試圖使用FindAncestor來查找網格並從那裏開始工作,但是我無法把它弄清楚。有沒有辦法綁定這兩個對象?如果是這樣如何?
而且它。我忘了那個語法。順便說一句,你只是修復了我在彈出窗口中遇到的另一個錯誤。謝謝! – Nathanael
@Nathanael:有時使用Popup對設置PlacementTarget非常有用,只是爲了提醒一下這個不錯的功能 – sll