How can I change WPF Button Image in Setter
I have a very strange problem trying to change the controltemplate for a
button in WPF (c#).
I now have the following code:
<Window.Resources>
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true"
Stroke="Black" StrokeThickness="1" StrokeDashArray="1
2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MacOSX-Close" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="Black" BorderThickness="0">
<Image x:Name="bgimg"
Source="bin/debug/Ressources/Images/GUI/frame-btn-defaulted.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="bgimg" Property="Source"
Value="bin/debug/Ressources/Images/GUI/frame-btn-defaulted.png"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
So this isn't working. It says
"{DependencyProperty.UnsetValue}" is no valid value for property
"System.Windows.Controls.Image.Source" on a setter.
And when I tried using multiple images in a grid (because you can only set
one child) and modified the "visibility" property, the button didn't show
up at all!!! No button, no image. And, yes, I am sure the image exists.
But the source is relative to the solution root, not to the compiled
program... does this matter? Please help me :) I'm gettin' little
desperate here... :(
Best regards ;) And please ask if somethin's not clear to you.
No comments:
Post a Comment