Hallo!
Auf dieser Seite gibt es ein kleines super Tutorial, das mich schon fast bis zum glück geführt hat:
http://www.silverlight-community.de/2010/12/contentplatzhalter-in-usercontrols/
Leider funktioniert das nicht ganz. Wenn ich alles gemacht habe was in dem Tut steht und dann in der Komponente Content platziere (und zwar ohne die komponente selber anzufassen, wie es ja der sinn in bei dieser technik ist), erscheint dieser nicht.
Hier ist mein code:
<UserControl x:Class="embedding.comp.UserControl1"
xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>"
xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>"
xmlns:d="<a href="http://schemas.microsoft.com/expression/blend/2008">http://schemas.microsoft.com/expression/blend/2008</a>"
xmlns:mc="<a href="http://schemas.openxmlformats.org/markup-compatibility/2006">http://schemas.openxmlformats.org/markup-compatibility/2006</a>"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Canvas x:Name="LayoutRoot">
<Canvas.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF286607"/>
<GradientStop Color="#FF6DF125" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
<Rectangle Fill="#FFF4F4F5" Stroke="Black" Height="25" Width="154" Canvas.Left="26" Canvas.Top="20" />
<Button Content="Irgendeine Aktion" Canvas.Left="26" Canvas.Top="49" />
<ContentControl Content="{Binding NewContent, ElementName=userControl}" Canvas.Left="51" Canvas.Top="75" Width="120" Height="60" />
<TextBlock Canvas.Left="8" TextWrapping="Wrap" Text="Unten" Canvas.Top="148" Foreground="#FFF93E3E"/>
<TextBlock Canvas.Left="8" TextWrapping="Wrap" Text="Oben" Foreground="#FFF93E3E"/>
<TextBlock Canvas.Left="-7" TextWrapping="Wrap" Text="Links" Foreground="#FFF93E3E" Canvas.Top="69">
<TextBlock.Projection>
<PlaneProjection RotationZ="90"/>
</TextBlock.Projection>
</TextBlock>
<TextBlock Canvas.Left="194" TextWrapping="Wrap" Text="Rechts" Foreground="#FFF93E3E" Canvas.Top="69">
<TextBlock.Projection>
<PlaneProjection RotationZ="90"/>
</TextBlock.Projection>
</TextBlock>
</Canvas>
</UserControl>
Codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Markup;
namespace embedding.comp
{
[ContentProperty("NewContent")]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public UIElement NewContent
{
get { return (UIElement)GetValue(NewContentProperty); }
set { SetValue(NewContentProperty, value); }
}
public static readonly DependencyProperty NewContentProperty =
DependencyProperty.Register("NewContent", typeof(UIElement), typeof(UserControl1), null);
}
}
Soweit ist doch alles richtig oder?
Nur eine sache fällt mir ein die auf ein problem hindeuten konnte. Als ich über der Klasse im Codebehind Block [ContentProperty("NewContent")] hinzugefügt hatte, musste ich ContentProperty erst auflösen, damit das ganze funktionierte. Das ding wurde dann in System.Windows.Markup gefunden.
Ist das eigentlich richtig so?
Ich hoffe ihr könnt mir helfen :)
Grüße,
A Learning Dude