我遇到了问题,有人可以告诉我这段代码有什么问题:
首先我创建2 Canvas:
private void AddItem()
{
Canvas myCanvas = new Canvas();
Canvas myCanvas2 = new Canvas();
myCanvas2.Height = 128;
myCanvas2.Width = 104;
myCanvas.Background = new SolidColorBrush(Colors.Blue);
myCanvas.Height = 200;
myCanvas.Width = 350;
myCanvas2.Margin = new System.Windows.Thickness(5,10,0,0);
myCanvas.Margin = new System.Windows.Thickness(66, 10, 0, 0);
然后我创建了三个Textblocks:
首先:将TextBlock添加到第一个Canvas:
TextBlock TextBlock1= new TextBlock();
TextBlock1.FontSize = 48;
TextBlock1.Text = Fach.Text;
Canvas.SetTop(TextBlock1, 10);
Canvas.SetLeft(TextBlock1, 29);
myCanvas.Children.Add(TextBlock1);
第二步:将第二个TextBlock添加到第一个Canvas:
TextBlock TextBlock2= new TextBlock();
TextBlock2.FontSize = 24;
TextBlock2.Text = Raum.Text;
Canvas.SetTop(TextBlock2, 79);
Canvas.SetLeft(TextBlock2, 31);
myCanvas.Children.Add(TextBlock2);
第三步:将第二个TextBlock添加到第二个Canvas:
TextBlock TextBlock3 = new TextBlock();
TextBlock3.FontSize = 20;
TextBlock3.Text = Zeit;
Canvas.SetTop(TextBlock3, 36);
Canvas.SetLeft(TextBlock3, 10);
myCanvas2.Children.Add(TextBlock3);
将myCanvas和myCanvas2添加到wrappanel:
wrapPanel.Children.Add(myCanvas);
wrapPanel.Children.Add(myCanvas2);
}
};
第一个Canvas(myCanvas)正在显示(盒子),但第二个Canvas(myCanvas2)应该出现在myCanvas前面。 Somone知道为什么吗?因为wappanel?我怎么能改变这个?
编辑:Xaml
<phone:PivotItem x:Name="Montag" Header="Montag" Margin="24,27,0,1">
<ScrollViewer VerticalScrollBarVisibility="Auto" >
<toolkit:WrapPanel x:Name="wrapPanel" Orientation="Vertical"/>
</ScrollViewer>
</phone:PivotItem>
答案 0 :(得分:1)
请仔细检查您的代码。我猜这条线不正确:
TextBlock3.Text = Zeit;
我认为你应该添加&#34; .Text&#34;到Zeit =&gt; &#34; Zeit.Text&#34 ;;
其他线条似乎是正确的。
希望帮助你。