Reputation: 351
I am using Blend for visual Studio 2012 and I have a problem, I need to change the image from a resource to three buttons
I convert an image to button
these resource is for one button:
<Window.Resources>
<Style x:Key="AppBtn" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Image x:Name="image" Source="1394235016_close.png" Stretch="None" Opacity="0.8" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" TargetName="image" Value="1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Button Style="{DynamicResource AppBtn}" Click="Button_Click" Margin="2,0,2,0" />
for one button is ok but I need to aply this resource to another two button but I need to change the image tag (for change the image)
how I do this?
Upvotes: 0
Views: 144
Reputation: 1000
I tested this and it worked
in your style do the following
<Image x:Name="image" Source="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=Tag}" Stretch="None" Opacity="0.8" />
and in your button
<Button x:Name="Search_Button" Click="Button_Click"
Style="{DynamicResource AppBtn}" Tag="your resource"/>
Change the tag in each button to give your image resource
Upvotes: 1
Reputation: 1000
Try this In the style template
<Image x:Name="image" Source="{TemplateBinding ImageSource}" Stretch="None" Opacity="0.8" />
and when you apply the button on page try following;
<local:AppBtn ImageSource="*yoursource*" />
<Button Style="{DynamicResource AppBtn}" Click="Button_Click" Margin="2,0,2,0" />
repeat for each button with different image source
Not sure it will work, but you can try
Upvotes: 0