2010-10-20 80 views
-1

這是我的用戶控件: -用戶控件添加到其他用戶控件

<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> 

在我MainPage.xaml.cs中我動態創建用戶控制,但它沒有得到建立。即使沒有例外被解僱。

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()); 
     } 
    } 

我在想什麼?此外,如果我添加textbox而不是用戶控件,它的工作原理。 在此先感謝:)

回答

-1

嘗試在xaml中添加一個ArcUserControl並查看它是否呈現。 canLayer1是什麼?

+0

謝謝,但只有高度和寬度缺少usercontrol。改變它並且工作! – TCM 2010-10-21 03:03:29

相關問題