locked
How to enable visual addition of children to a UserControl (Christian Kihm) - 3/26/2007 2:22 AM PST RRS feed

  • Question

  • By: Christian Kihm

    Hi,
    
    I wrote some UserControls to generalize some forms. Within this UserControls 
    are other standart Controls like GroupBox whichs content property should be 
    bound to a DependencyProperty of the UserControl. This works fine if I add 
    the Childrens to the DependencyProperty within the XAML code. However, it is 
    not possible to Drag childrens in the Custom Control visual. For example I 
    add this symplified Code Snippet:
    
    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="UntitledProject1.UserControl1"
    	x:Name="UserControl"
    	Width="640" Height="480">
    
    	<Grid x:Name="LayoutRoot">
    		<GroupBox HorizontalAlignment="Left" 
    					 VerticalAlignment="Top" 
    					 Header="Information" 
    					 Content="{Binding Path=Information, ElementName=UserControl, 
    Mode=Default}"/>
    	</Grid>
    </UserControl>
    
    When I use this UserControl in a Window, it is not possible to Drag for 
    example a Button into the GroupBox. Is it possible to archive this? The 
    dragged child should be set the "Information" property.
    
    Thanks for your efforts
    Christian
    Tuesday, February 19, 2008 10:46 PM

Answers

  • By: Adrian Mascarenhas (MS)

    You are right. This does look like a bug. I will follow up with the feature
    team.
    As a workaround, you will have to edit the xaml directly as you mention.

    --
    - Adrian Mascarenhas (MSFT), Expression Blend
    "Content is provided "AS IS" with no warranties and confers no rights.
    Opinions are my own and do not represent those of my employer. "


    "Christian Kihm" <Christian Kihm@discussions.microsoft.com> wrote in message
    news:4A959780-923C-4B8C-8B31-803F8538CC4E@microsoft.com...

    Click to show or hide original message or reply text.
    Tuesday, February 19, 2008 10:57 PM

All replies

  • By: Adrian Mascarenhas (MS)

    You are right. This does look like a bug. I will follow up with the feature
    team.
    As a workaround, you will have to edit the xaml directly as you mention.

    --
    - Adrian Mascarenhas (MSFT), Expression Blend
    "Content is provided "AS IS" with no warranties and confers no rights.
    Opinions are my own and do not represent those of my employer. "


    "Christian Kihm" <Christian Kihm@discussions.microsoft.com> wrote in message
    news:4A959780-923C-4B8C-8B31-803F8538CC4E@microsoft.com...

    Click to show or hide original message or reply text.
    Tuesday, February 19, 2008 10:57 PM
  • By: Unni Ravindranathan (MS)


    This is not possible in v1 Blend. We specially handle certain properties
    like the Content of a ContentControl (Button, CheckBox, etc) and Header for
    a HeaderedContentControl (Expander, etc). You cannot add your own property
    to this set.

    Thanks,
    -Unni

    "Christian Kihm" <Christian Kihm@discussions.microsoft.com> wrote in message
    news:4A959780-923C-4B8C-8B31-803F8538CC4E@microsoft.com...
    > Hi,
    >
    > I wrote some UserControls to generalize some forms. Within this
    > UserControls
    > are other standart Controls like GroupBox whichs content property should
    > be
    > bound to a DependencyProperty of the UserControl. This works fine if I add
    > the Childrens to the DependencyProperty within the XAML code. However, it
    > is
    > not possible to Drag childrens in the Custom Control visual. For example I
    > add this symplified Code Snippet:
    >
    > <UserControl
    > xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    > xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    > x:Class="UntitledProject1.UserControl1"
    > x:Name="UserControl"
    > Width="640" Height="480">
    >
    > <Grid x:Name="LayoutRoot">
    > <GroupBox HorizontalAlignment="Left"
    > VerticalAlignment="Top"
    > Header="Information"
    > Content="{Binding Path=Information, ElementName=UserControl,
    > Mode=Default}"/>
    > </Grid>
    > </UserControl>
    >
    > When I use this UserControl in a Window, it is not possible to Drag for
    > example a Button into the GroupBox. Is it possible to archive this? The
    > dragged child should be set the "Information" property.
    >
    > Thanks for your efforts
    > Christian
    Tuesday, February 19, 2008 10:58 PM
  • By: Christian Kihm

    Ok, thanks for your hint. But however, even when I modify the example of
    above to use a ControlTemplate and bind the Content of the GroupBox via
    TemplateBinding to the Content Property, this still not work:


    <UserControl
    xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="UntitledProject1.UserControl1"
    x:Name="UserControl"
    Width="640" Height="480">
    <UserControl.Template>
    <ControlTemplate>
    <Grid x:Name="LayoutRoot">
    <GroupBox HorizontalAlignment="Left"
    VerticalAlignment="Top"
    Header="Information"
    >
    <ContentPresenter
    Margin="{TemplateBinding Control.Padding}"
    SnapsToDevicePixels="{TemplateBinding
    UIElement.SnapsToDevicePixels}"
    Content="{TemplateBinding ContentControl.Content}"
    />
    </GroupBox>
    </Grid>
    </ControlTemplate>
    </UserControl.Template>
    </UserControl>

    When I understand your post right then at least this should be possible. As
    mentioned before, all work fine within XAML, but we would like to use drag
    and drop within blend to set the content.

    And one more question. Do consider to add the possibility to add custom
    propertys to the set of "Content" properties?

    Thanks and best regards
    Christian

    "Unni Ravindranathan (MS)" wrote:

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 10:59 PM
  • By: vijay
    Hi, this is vijay i need information regarding usercontrols like

    * creating usercontrol in wpf

    * what are the custom property for user controls

    *with examples

    Tuesday, February 19, 2008 11:00 PM
  • By: Unni Ravindranathan (MS)

    For examples of UserControl, look at some of the samples we have in the
    product - for example, the Grand Piano sample has a volume knob control.

    Also, check out help documentation to get some information on UserControls
    (F1).

    Thanks,
    -Unni

    "vijay" <vijay@discussions.microsoft.com> wrote in message
    news:D0E32978-9CE5-47B7-919A-D2D4903F6D6F@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 11:00 PM
  • By: Unni Ravindranathan (MS)
    We have explicitly disabled drag and drop into UserControls (and anything
    derived from UserControl). If you were to change the base of the markup to
    be Button (so that the Control you are defining derived from Button), I
    would expect things to work.

    Thanks,
    -Unni

    "Christian Kihm" <ChristianKihm@discussions.microsoft.com> wrote in message
    news:ED79AF26-19A4-471A-BFCA-BDA3D05398A8@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 11:01 PM