UserControl的按钮在App.xaml中定义了Style="{StaticResource MenuIconByttonStyle}"
,但在xaml窗口中使用此UserControl会出错:
“菜单按钮” TargetType与元素“按钮”的类型不匹配
不确定MenuButton指的是什么,因为我在任何地方都找不到。
如果我使用StaticResource MenuIconButtonStyle2
或FlatToolbarButton
,则不会出现此错误。
为什么会这样?
App.xaml:
<Application.Resources>
<Style x:Key="FlatToolbarButton" TargetType="Button">
<Setter Property="Width" Value="16"/>
<Setter Property="Height" Value="16"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="0"/>
</Style>
<Style x:Key="MenuIconButtonStyle" TargetType="Button" BasedOn="{StaticResource FlatToolbarButton}" >
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Background="#333333">
<Border CornerRadius="0" BorderThickness="0" BorderBrush="#333333">
<Image Source="{StaticResource MenuIcon}" Stretch="UniformToFill"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Background="Aqua">
<Border CornerRadius="0" BorderThickness="1" BorderBrush="Aqua">
<Image Source="{StaticResource MenuIcon}" Stretch="UniformToFill"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="MenuIconButtonStyle2" TargetType="Button" BasedOn="{StaticResource FlatToolbarButton}" >
<Setter Property="Background" Value="{StaticResource MenuIconBrush}"/>
</Style>
TradeListUC.xaml:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="18"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Background="#333333" >
<Label x:Name="TitleLabel" FontSize="12" Content="Trade List" Height="16" Width="100"
VerticalAlignment="Top" Padding="4,0,0,0" Foreground="White" />
<StackPanel DockPanel.Dock="Right" HorizontalAlignment="Right" Orientation="Horizontal" >
<TextBox x:Name="SymbolEntryTb" Width="100" Margin="0,0,1,0"
Background="#999999" BorderBrush="#AAAAAA"
HorizontalAlignment="Right" Padding="0,-1,0,0" />
<Button x:Name="MenuBtn" Style="{StaticResource MenuIconButtonStyle}">
</Button>
</StackPanel>
</DockPanel>
MainWindow.xaml:
<TabItem Header="Trades">
<Grid>
<UC:TradeListUC/>
</Grid>
</TabItem>