var el1 = new Ellipse();
var el2 = new Rectangle();
ContentPanel.Children.Add(el1);画面に配置されているGridクラスでは、自身の中に組み込まれているコントロール類を「Children」というプロパティで管理しています。このプロパティには「UIElementCollection」というコレクションクラスのインスタンスが設定されており、そこにコントロール類がまとめられています。このコレクションに「Add」メソッドで組み込んでやれば、Gridに図形が追加され表示される、というわけです。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; namespace PhoneApp1 { public partial class MainPage : PhoneApplicationPage { // コンストラクター public MainPage() { InitializeComponent(); draw(); } public void draw() { var el1 = new Ellipse(); el1.HorizontalAlignment = HorizontalAlignment.Left; el1.VerticalAlignment = VerticalAlignment.Top; el1.Width = 200; el1.Height = 200; el1.Fill = new SolidColorBrush(Colors.Blue); el1.Margin = new Thickness(50, 100, 10, 10); ContentPanel.Children.Add(el1); var el2 = new Rectangle(); el2.HorizontalAlignment = HorizontalAlignment.Left; el2.VerticalAlignment = VerticalAlignment.Top; el2.Width = 200; el2.Height = 200; el2.Fill = new SolidColorBrush(Colors.Red); el2.Margin = new Thickness(150, 200, 10, 10); ContentPanel.Children.Add(el2); } } }
<< 前へ | 次へ >> |