Skip to main content

Microsoft Silverlight

Answered Question Accessing Control in UserControlRSS Feed

(0)

schakal242
schakal242

Member

Member

18 points

55 Posts

Accessing Control in UserControl

Hello,

 i have created an UserControl:

 

<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="Main.shadow"
d:DesignWidth="640" d:DesignHeight="480" x:Name="MyShadow">


<Border CornerRadius="13" BorderThickness="1,1,1,1" BorderBrush="#19000000" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border CornerRadius="12" BorderThickness="1,1,1,1" BorderBrush="#33000000" >
<Border CornerRadius="11" BorderThickness="1,1,1,1" BorderBrush="#66000000">
<Border CornerRadius="11" BorderThickness="1,1,1,1" BorderBrush="#99000000">
<Border CornerRadius="10" BorderThickness="1,1,1,1" BorderBrush="#FF000000">
<Border CornerRadius="10" BorderThickness="1,1,1,1" BorderBrush="#FF000000" x:Name="myBorder" Background="{StaticResource MyBackground}">
<Canvas Width="150" Height="150">
</Canvas>
</Border>
</Border>
</Border>
</Border>
</Border>
</Border>


</UserControl>

  

When i reuse this UserControl, how can i access and add items to the containing Canvas?

Like that:

 <Main:shadow Height="131" HorizontalAlignment="Left" Margin="100,115,0,0" VerticalAlignment="Top" Width="158"

    ...add some controls here

</Main:shadow
        

billsm
billsm

Participant

Participant

1371 points

489 Posts

Re: Accessing Control in UserControl

have you tried to use ajax?? or jquery???

 

billsm
billsm

Participant

Participant

1371 points

489 Posts

Re: Accessing Control in UserControl

if you need to reuse user control you can use styles

her's jesse liberty video

http://silverlight.net/learn/learnvideo.aspx?video=69796

sl.ayer
sl.ayer

Participant

Participant

850 points

163 Posts

Re: Accessing Control in UserControl

Give canvas x:Name. If you call canvas "myCanvas" then you can do this: myControl.myCanvas.Children.Add(something);

schakal242
schakal242

Member

Member

18 points

55 Posts

Re: Accessing Control in UserControl

Hi,

i know.

But i want to access the canvas in XAML not in code...

sl.ayer
sl.ayer

Participant

Participant

850 points

163 Posts

Re: Accessing Control in UserControl

I see. In that case you can't use UserControl. You should derive your control from ContentControl.

MarkTap
MarkTap

Participant

Participant

1442 points

263 Posts

Re: Accessing Control in UserControl

This thread might help get you part of the way through this: http://silverlight.net/forums/t/33540.aspx

 

schakal242
schakal242

Member

Member

18 points

55 Posts

Answered Question

Re: Accessing Control in UserControl

Hai!

Thanks for your reply.

Now i found this solution:

The XAML i need in myControl is of type canvas

<Canvas x:Class="MyProject.MyControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="Auto" Height="Auto">
</Canvas>

The code for the control:

using System.Windows.Controls;

namespace MyProject
{
    public partial class MyControl : Canvas
    {
        public MyControl()
        {
            //InitializeComponent();
        }
    }
}

And the usage of MyControl:

 

<MyProject:MyControl Height="138" HorizontalAlignment="Left" Margin="100,0,0,117" VerticalAlignment="Bottom" Width="205">
            <Button Height="25" Width="82" Content="Button" Canvas.Left="0" Canvas.Top="0"/>
            <Button Height="25" Width="82" Content="Button" Canvas.Left="0" Canvas.Top="30"/>
</MyProject:MyControl>

 

Still working. Maybe adding some finetuning..

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities