Reputation: 1011
Could someone help with this.
Im trying to make the following code so that i can inject what ever image i want into this button style. as this button style is used throughout the whole application
<Style TargetType="Button" x:Key="ButtonIsChecked">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox Content="{Binding Content}" Name="CheckBox_Logon" IsHitTestVisible="False" IsChecked="False">
<CheckBox.Template>
<ControlTemplate TargetType="{x:Type CheckBox}">
<WrapPanel>
<Image
Source="/AdminUltimate;component/Images/Icons/Windows.ico"
Width="15" Margin="3"
Visibility="{Binding IsChecked, Converter={StaticResource BoolToVis}, ElementName=DisableIcons}"/>
<TextBlock Text="{Binding}" VerticalAlignment="Center"/>
</WrapPanel>
</ControlTemplate>
</CheckBox.Template>
</CheckBox>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Current Usage
<Button Content="Login" Style="{StaticResource ButtonIsChecked}"/>
i would like to do something like
<Button Content="Login" Style="{StaticResource ButtonIsChecked}" imgsrc="Pathtoimage"/>
Is this possible?
Upvotes: 0
Views: 302
Reputation: 23270
Something quick and easy to use to piggy back a dependency string through is Tag like;
<Style TargetType="Button" x:Key="ButtonIsChecked">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Tag" Value="/Default/Image/Path.jpg"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox Content="{Binding Content}" Name="CheckBox_Logon" IsHitTestVisible="False" IsChecked="False">
<CheckBox.Template>
<ControlTemplate TargetType="{x:Type CheckBox}">
<WrapPanel>
<Image
Source="{TemplateBinding Tag}"
Width="15" Margin="3"
Visibility="{Binding IsChecked, Converter={StaticResource BoolToVis}, ElementName=DisableIcons}"/>
<TextBlock Text="{Binding}" VerticalAlignment="Center"/>
</WrapPanel>
</ControlTemplate>
</CheckBox.Template>
</CheckBox>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Then implement like;
<Button Style="{StaticResource ButtonIsChecked}" Tag="/AdminUltimate;component/Images/Icons/Windows.ico"/>
Hope this helps.
Upvotes: 2