我有一個 MenuItem,在這個 MenuItem 中我添加了一個 ItemSource,這樣這個 menuItem 的專案是從 Observable 集合中創建的。我的 MenuItem 看起來像這樣:
<MenuItem Foreground="Black"
FontFamily="{Binding ElementName=wpfAudit, Path=FontFamily}"
FontSize="{Binding ElementName=wpfAudit, Path=FontSize}"
FontWeight="{Binding ElementName=wpfAudit, Path=FontWeight}"
Header="Artikellabel Drucker"
ItemsSource="{Binding ocArtikellabeldrucker, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
</MenuItem>
現在我想編輯我用 ItemSource 創建的專案的 MenuItem.Icon。
我試過的是這樣的:
<MenuItem.Resources>
<RadioButton x:Key="RadioButtonResource" x:Shared="false" HorizontalAlignment="Center"
GroupName="MenuItemRadio" IsHitTestVisible="False" IsChecked="{Binding IstDrucker}" Style="{StaticResource {x:Type RadioButton}}"/>
</MenuItem.Resources>
但是這很管用。那么我怎樣才能讓它發揮作用呢?也許使用 ControlTemplate ?
uj5u.com熱心網友回復:
像下面這樣的東西會起作用
<Style x:Key="MenuItemStyle" TargetType="{x:Type MenuItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<StackPanel Orientation="Horizontal">
<RadioButton IsChecked="True" Content="Test Item" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/313953.html
