Hey
I try to extend a Button Control (it's from Telerik, but it should work everywhere...)
I want to add a Property called "NormalImage" and "MouseOverImage". So, I did the following in Codebehind:
Partial Public Class Extensions
Inherits Telerik.Windows.Controls.RadButton
Public Shared ReadOnly NormalImageProperty As DependencyProperty = _
DependencyProperty.RegisterAttached("NormalImage", _
GetType(ImageSource), _
GetType(Extensions), New UIPropertyMetadata())
Public Shared Function GetNormalImage(obj As DependencyObject) As ImageSource
Return DirectCast(obj.GetValue(NormalImageProperty), ImageSource)
End Function
Public Shared Sub SetNormalImage(obj As DependencyObject, value As ImageSource)
obj.SetValue(NormalImageProperty, value)
End Sub
Public Shared ReadOnly MouseOverImageProperty As DependencyProperty = _
DependencyProperty.RegisterAttached("MouseOverImage", _
GetType(ImageSource), _
GetType(Extensions), New UIPropertyMetadata())
Public Shared Function GetMouseOverImage(obj As DependencyObject) As ImageSource
Return DirectCast(obj.GetValue(MouseOverImageProperty), ImageSource)
End Function
Public Shared Sub SetMouseOverImage(obj As DependencyObject, value As ImageSource)
obj.SetValue(MouseOverImageProperty, value)
End Sub
End ClassAnd then, I created a Template for the Button in a Resourcedictionary:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:ext="clr-namespace:StudioWPF.Extensions.TelerikEx.RadButton"><!-- Hier werden Einträge für Ressourcenverzeichnisse definiert. --><Style x:Key="extButton" TargetType="telerik:RadButton"><Setter Property="Margin" Value="10" /><Setter Property="Cursor" Value="Hand" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="telerik:RadButton"><Grid x:Name="Root" ><Grid.Background><LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5" ><GradientStop Color="#FF4B5156"/><GradientStop Color="#FF1F81EC" Offset="1"/></LinearGradientBrush></Grid.Background><Image x:Name="myImage" Width="38" Height="38" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="{Binding NormalImage, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ext:Extensions}}}" /></Grid><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="true"><Setter TargetName="myImage" Property="Source" Value="{Binding MouseOverImage, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ext:Extensions}}}"/></Trigger>
...And in the WPF UserControl I use the following XAML Code:
<telerik:RadButton Style="{StaticResource extButton}"
Width="35"
HorizontalAlignment="Left"
ext:Extensions.IsFadeEnabled="True"
ext:Extensions.NormalImage="/StudioWPF;component/Styles/Images/64x64/m_Col/contact.png"
ext:Extensions.MouseOverImage="/StudioWPF;component/Styles/Images/64x64/v_Col/contact.png">The problem is, I can see the background, but no Image is presented, not the NormalImage and not the MouseOverImage.
Can someone please can take a look and tell me, what I am doing wrong!?
THX a lot - Have a nice day