Yes, it is possible, and here is some code that I used to compose presentations from UserControls with DP.
I don't like it much, but it works. I also think this is a great topic, and maybe some code will help get the best answers!
Cheers
Berry
UserControl XAML
<Button x:Name="btnAddNewItem" Style="{StaticResource blueButtonStyle}" > <StackPanel Orientation="Horizontal"> <Image Source="{resx:Resx ResxName=Core.Presentation.Resources.MasterDetail, Key=bullet_add}" Stretch="Uniform" /> <Label x:Name="tbItemName" Margin="5" Foreground="White" Padding="10, 0">_Add New [item]</Label> </StackPanel> </Button>
UserControl Behind Code
public partial class AddNewItemButton : UserControl { ... #region Item Name public static readonly DependencyProperty ItemNameProperty = DependencyProperty.Register( "ItemName", typeof(string), typeof(AddNewItemButton), new FrameworkPropertyMetadata(OnItemNameChanged)); public string ItemName { get { return (string)GetValue(ItemNameProperty); } set { SetValue(ItemNameProperty, value); } } public string ButtonText { get { return (string) tbItemName.Content; } } private static void OnItemNameChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) {
Another UserControl element showing composition
<UserControl ... xmlns:uc="clr-namespace:Smack.Core.Presentation.Wpf.Controls.UserControls" > <DockPanel LastChildFill="True"> ... <uc:AddNewItemButton x:Name="_addNewItemButton" Margin="0,0,10 0" DockPanel.Dock="Right" /> ... </DockPanel> </UserControl>
source share