2012-08-09 69 views
1

如何以編程方式添加N個元素到WP7控件,以便它們在彼此之下(目前我全部在一個地方並且彼此重疊)?添加UI元素WP7

//this code N times 
TextBlock block = new TextBlock(); 
block.Text = message.Body; 
ContentPanel.Children.Add(block); 

回答

0
private Ellipse GenerateEllipse() 
{ 
    Ellipse element = new Ellipse(); 
    element.Fill = new SolidColorBrush(Colors.White); 
    element.Height = 8.0; 
    element.Width = 8.0; 
    this.ContentPanel.Children.Add(element); 
    return element; 
} 

之後,你怎麼稱呼在方法爲週期。

希望這會有所幫助。

1

這裏的基本問題是你添加的元素的x座標和y座標都是一樣的。因此,他們都在一個地方。由於網格佈局沒有考慮到這一點。

答案是使用stackpanel或單獨定義uielement.margin;值。 邊距基本上是一個厚度元素。 我遇到了同樣的問題,但後來改變了我的元素的x和y座標。我用 uielement.margin.left = previousUiElement.margin.left + 6; uielement.margin.top = previousUiElement.margin.top + 36;

更改6無論您的要求是什麼。