Adding usercontrol to another user control
This is my user control :-
<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"
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
mc:Ignorable="d"
x:Class="NiceAnimation.ArcUserControl"
d:DesignWidth="72" d:DesignHeight="72">
<Grid x:Name="LayoutRoot">
<ed:Arc x:Name="arcControl" ArcThickness="20" ArcThicknessUnit="Pixel" EndAngle="360" Fill="#FFFF8700" Stretch="None" Stroke="Black" StartAngle="0" UseLayoutRounding="False" StrokeThickness="0"/>
</Grid>
</UserControl>
In my MainPage.xaml.cs i am creating the user control dynamically but it's not getting created. Even no exception is fired.
public partial class MainPage : UserControl
{
public MainPage()
{
// Required to initialize variables
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
Random objRandom = new Random();
for (int intIndex = 0; intIndex < 30; intIndex++)
{
ArcUserControl objArcUserControl = new ArcUserControl();
objArcUserControl.Opacity = 0.7;
//objArcUserControl.SetValue(Canvas.LeftProperty, (double) objRandom.Next(10, 640));
//objArcUserControl.SetValue(Canvas.TopProperty, (double)objRandom.Next(10, 480));
objArcUserControl.MouseEnter += new MouseEventHandler(objArcUserControl_MouseEnter);
//MainCanvas.Children.Add(objArcUserControl);
开发者_高级运维 canLayer1.Children.Add(objArcUserControl);
// canLayer2.Children.Add(objArcUserControl);
// canLayer3.Children.Add(objArcUserControl);
}
}
void objArcUserControl_MouseEnter(object sender, MouseEventArgs e)
{
MessageBox.Show(e.GetPosition(this).ToString());
}
}
What am i missing ? Further if i add textbox
instead of usercontrol it works.
Thanks in advance :)
try just adding an ArcUserControl in xaml and see if it renders. what is canLayer1?
精彩评论