Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Accessing Control in UserControl
7 replies. Latest Post by schakal242 on April 1, 2009.
(0)
schakal242
Member
18 points
55 Posts
03-27-2009 3:21 PM |
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
Participant
1371 points
489 Posts
03-29-2009 3:35 PM |
have you tried to use ajax?? or jquery???
03-29-2009 3:40 PM |
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
850 points
163 Posts
03-29-2009 4:59 PM |
Give canvas x:Name. If you call canvas "myCanvas" then you can do this: myControl.myCanvas.Children.Add(something);
03-31-2009 5:47 PM |
Hi,
i know.
But i want to access the canvas in XAML not in code...
04-01-2009 4:12 AM |
I see. In that case you can't use UserControl. You should derive your control from ContentControl.
MarkTap
1442 points
263 Posts
04-01-2009 8:20 AM |
This thread might help get you part of the way through this: http://silverlight.net/forums/t/33540.aspx
04-01-2009 6:38 PM |
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..