0
我開始在WindowsPhone中開發應用程序,並遇到一些問題。我試圖動態添加畫布,但它不起作用,我可能忘記了某些內容,可否幫助我發現我的錯誤?下面的代碼來自我的學習應用程序,它是基本的Win Phone應用程序。動態創建畫布
CS代碼:
public MainPage()
{
InitializeComponent();
int size = 50;
Canvas myCanvas = new Canvas();
Canvas.SetLeft(myCanvas, 0);
myCanvas.Width = size;
Color c = new Color();
c.R = 255;
c.B = 0;
c.G = 255;
myCanvas.Background = new SolidColorBrush(c);
ContentPanel.Height = 100;
ContentPanel.Width = 100;
ContentPanel.Children.Add(myCanvas);
ApplicationTitle.Text = ContentPanel.ActualHeight.ToString();
}
XAML
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
</Grid>
</Grid>
謝謝你,你讓我很快樂;) 目前,我試圖創建一個遊戲,我需要,我會很快把一些PNG可拖動的元素。 – 2012-04-21 13:45:02
很高興幫助。祝你好運! – Robaticus 2012-04-21 14:01:53