Ok vielen Dank für die Antwort. Da ich die Controllibrary später nicht mehr templaten kann fällt die Variante für mich schon mal raus. Controllibrary bedeutet ja auch gleichzeitig, dass es ein UserControl ist richtig? Zumindest habe ich in Blend oder im Studio die Möglichkeit ein Projekt Controllibrary anzulegen, dass dann gleichzeitig sofort als UserControl angelegt wird. Die Geschichte mit dem CustomControl würd mich schon interessieren. In der Hilfe von Blend komme ich zu dem Artikel "Try it: Create a custom WPF control". Da wird das mit dem ImageButton erklärt. Wenn dass das CustomControl ist was du angesprochen hast weiß ich wie es funktioniert. Oder meintest du noch etwas anderes? Wegen dem UserControl poste ich mal den Code. Vielleicht kann man da sehen was ich falsch gemacht habe. Das UserControl habe ich im Studio erst von Button geerbt und dann in Blend weiter bearbeitet. Dann habe ich die DLL genommen und mit Blend in ein anderes Projekt eingebunden. Das Control sehe ich aber ich kann habe das SourceProperty nicht usw.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="ImageButtonLibrary.UserControl1"
x:Name="UserControl"
d:DesignWidth="640" d:DesignHeight="480" xmlns:ImageButtonLibrary="clr-namespace:ImageButtonLibrary">
<UserControl.Resources>
<Style x:Key="ImageButtonStyle1" TargetType="{x:Type ImageButtonLibrary:ImageButton}">
<Setter Property="Template" Value="{DynamicResource ImageButtonControlTemplate1}"/>
</Style>
<ControlTemplate x:Key="ImageButtonControlTemplate1" TargetType="{x:Type ImageButtonLibrary:ImageButton}">
<Grid Width="100" Height="100">
<Ellipse Fill="#FFFFFFFF" Stroke="#FF000000"/>
<Image Source="{TemplateBinding Source}"/>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Content="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<ImageButtonLibrary:ImageButton HorizontalAlignment="Left" Style="{DynamicResource ImageButtonStyle1}" VerticalAlignment="Top"/>
</Grid>
</UserControl>
public class ImageButton : Button
{
public ImageSource Source
{
get { return base.GetValue(SourceProperty) as ImageSource; }
set { base.SetValue(SourceProperty, value); }
}
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(ImageSource), typeof(ImageButton));
}
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ImageButtons.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480" xmlns:ImageButtons="clr-namespace:ImageButtons" xmlns:ImageButtonLibrary="clr-namespace:ImageButtonLibrary;assembly=ImageButtonLibrary">
<Grid x:Name="LayoutRoot">
<ImageButtons:ImageButton HorizontalAlignment="Left" x:Name="btn1" Style="{DynamicResource ImageButtonStyle2}" VerticalAlignment="Top" Content="" Click="btn1_Click" Height="24" Width="35"/>
<ImageButtonLibrary:ImageButton HorizontalAlignment="Left" Margin="0,28,0,0" VerticalAlignment="Top" Content="ImageButton" Width="73.067"/>
<ImageButtonLibrary:UserControl1 HorizontalAlignment="Left" VerticalAlignment="Top" Height="Auto" Width="Auto" Margin="104,28,0,0" x:Name="userButton" MouseLeftButtonUp="userButton_MouseLeftButtonUp"/>
</Grid>
</Window>
private void userButton_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ImageSource myImage = FindResource("close") as ImageSource;
//userButton.So
}
Kombiniere...