Skip to main content

Microsoft Silverlight

Unanswered Question Working User Control Sample with two Content Controls RSS Feed

(0)

UlissesP
UlissesP

Member

Member

1 points

3 Posts

Working User Control Sample with two Content Controls

Hi, Normal 0 false false false EN-GB X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}

I'm trying to create a user control with 2 Content Controls.

 This user control (that would contain some buttons) would be reused in several pages/forms having the Content Controls customized to have additional buttons and textboxes.

 Although there's a lot of information about Content Controls, most examples are only compatible with the Beta Versions of Silverlight or are just using one Content control, that since it's the Default Content Control it does not need to be named.

 Does anyone know where can I find a code sample of a user control like this and with the code of page using it?

Thanks,

Ulisses

Amanda Wang - MSFT
Amanda W...

All-Star

All-Star

17241 points

1,466 Posts

Re: Working User Control Sample with two Content Controls

Hi Ulisses,

 

UlissesP:
Although there's a lot of information about Content Controls, most examples are only compatible with the Beta Versions of Silverlight or are just using one Content control, that since it's the Default Content Control it does not need to be named.

Do you want to use tow ContentControls in the user control, and named one contentControl and using it with code?

You can try to refer below code,

1. The xaml code with two ContentControls.One has the name, the othere does not have.

<UserControl
    x:Class=”Simple.Page”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
    Background=”Olive”  Width=”400″ Height=”300″>
    <UserControl.Resources>
        <DataTemplate x:Key=”Circle”>
            <Ellipse Width=”20″ Height=”20″ Fill=”Red”></Ellipse>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name=”LayoutRoot” Background=”White”>
        <Popup x:Name=”MyPopup”IsOpen=”False”>
            <ContentControl ContentTemplate=”{StaticResource Circle}”  Opacity=”0.5″/>
        </Popup>
        <ContentControl  ContentTemplate=”{StaticResource Circle}”  x:Name=”MyControlToMove” />
    </Grid>
</UserControl>

2. then you can use the ContentControl MyControlToMove in the code, like below:

void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    if (!_captured)   return;
    MyPopup.ReleaseMouseCapture();
    MyPopup.IsOpen = false;
    _captured = false;
    GeneralTransform gt = this.TransformToVisual(MyControlToMove);
    PointstartPoint = gt.Transform(new Point(0, 0));
    Pointp = e.GetPosition(null);
    TranslateTransformtt = new TranslateTransform();
    tt.X = p.X - _horisontalOffset - startPoint.X;
    tt.Y = p.Y - _verticalOffset - startPoint.Y;
    MyControlToMove.RenderTransform = tt;

}

Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

UlissesP
UlissesP

Member

Member

1 points

3 Posts

Re: Working User Control Sample with two Content Controls

Hi Amanda,

 That code is close to what I needed, except that I was thinking about something a bit more complex.

I didn't want that the user control was located in the same form/user control that has the code that is using it. I suppose that to have this working I'll need more code, eventually using the OnApplyTemplate method. Do you have any sample like this?

 

Regards,

Ulisses Pinto

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities