<ControlTemplate x:Key="ItemButton" TargetType="{x:Type Button}"> <Border BorderBrush="Transparent" BorderThickness="0"> <WrapPanel VerticalAlignment="Bottom" HorizontalAlignment="Center"> <Image Source="{TemplateBinding Button.Background}"></Image> <TextBlock Text="{TemplateBinding Content}" FontSize="14" FontWeight="Bold" /> </WrapPanel> </Border> </ControlTemplate>
我想设置一个上面是图片,下面是文字的按钮
<Button Content="工具" Foreground="White" Template="{StaticResource ItemButton}"
Width="60" Height="63"> <Button.Background> <ImageBrush Stretch="Uniform" ImageSource="tool.jpg" /> </Button.Background> </Button>
但{TemplateBinding Button.Background}绑定不到ImageSource,我尝试用类似{TemplateBinding (Button.Background).(ImageBrush.ImageSource)}这样的方式,但VS提示没有找到ImageBrush这个元素,请教到底应该如何绑定呢?
乱七八糟的绑定,好好看看基础吧
<Button Height="85" Name="button1" Width="95" > <WrapPanel Margin="1" Orientation="Horizontal" Width="80"> <Image Source="/Test;component/Images/1.png" Height="40" Width="80"/> <TextBlock Text="图片按钮"/> </WrapPanel> </Button>
非样式绑定
你是给按钮设动态的背景还是干啥?