下面是我对按钮的代码:水平对齐
<Button //namespaces
x:Class="myProject.MyButton"
FocusVisualStyle="{x:Null}"
Foreground="White"
Height="60"
Width="200"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Padding="0 0 1 1"
>
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border" CornerRadius="8">
<Border.Background>
#006BB7
</Border.Background>
<DockPanel Margin="3">
<Image Source="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}" Height="30" Stretch="Fill" Margin="0 0 0 0" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" FontSize="20" VerticalAlignment="Center" Padding="10,0,10,0" HorizontalAlignment="Left"/>
<Image Source="{DynamicResource ResourceKey=Bmp}" Height="30" Width="30" HorizontalAlignment="Right" Margin="0 0 10 0"></Image>
</DockPanel>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
当我这样称呼它:
<ui:MyButton x:Name="btnGo" Tag="/Resources/Go.png" Content="Go" Command="{Binding Path=GoCommand}" Margin="20 0 0 0"/>
,一切看起来像我希望它看起来:第一图像ISN不显示,按钮的第三部分(第二个图像)右对齐。
然而,在这里:
<ui:MyButton Margin="10" Content="{Binding MyName}" Tag="{Binding Path}" HorizontalAlignment="Center" VerticalAlignment="Top">
<Button.Resources>
<BitmapImage x:Key="Bmp" UriSource="/Images/arrowRight.png"></BitmapImage>
</Button.Resources>
</ui:MyButton>
WHN我这样调用按钮,文本和第二图像不显示。所有显示的是第一个图像,并通过整个按钮的宽度拉伸。这是为什么发生?我想让这个行为像另一个行为一样。
,然后添加适当的'DependencyProperty'来绑定到你的两个'ImageSource'属性。 – Sheridan
@Sheridan我没有定义按钮的类。 –
那么这是什么:'