【发布时间】:2012-10-15 13:35:01
【问题描述】:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CuratioCMS.Client.UI.Controls">
<Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type local:ImageButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ImageButton}">
<StackPanel Height="Auto" Orientation="Horizontal">
<Image Width="20"
Height="20"
Margin="10,4,0,4"
Source="{Binding Path=Image,
RelativeSource={RelativeSource TemplatedParent}}"
Stretch="Fill" />
<TextBlock Margin="5,0,10,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="12"
FontWeight="Bold"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Label}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这是 Generic.xaml 中用于 ImageButton 自定义控件的代码。 whit 可以按预期工作,但我不能从 Base button stale 继承,所以这种样式不是从 Button 继承所有基本样式,而是只创建没有任何基本样式的自定义控件,并且就
BasedOn="{StaticResource {x:Type Button}}"
在 VS 内部显示错误 Resource '{x:Type System.Windows.Controls.Button}' is not found
我不知道如何实现所需的样式以及为什么在 Visual Studio 编辑器中显示此错误消息
【问题讨论】:
标签: wpf xaml custom-controls