簡體   English   中英

WP8:以編程方式創建的文本塊未顯示在應用程序中?

[英]wp8: programmatically created textblock is not displayed in app?

好,

我已經在C#中以編程方式創建了textblock 但未在應用中顯示。 怎么了 ?

這是我更新的C#代碼:

            double left = 0, top = 15, right = 0, bottom = 0;
            double left1 = 0, top1 = 12, right1 = 0, bottom1 = 12;
            TextBlock fileName = new TextBlock();
            fileName.Margin = new Thickness(left, top, right, bottom);
            fileName.FontSize = 30;
            fileName.Foreground = new SolidColorBrush(Colors.White);
            fileName.TextAlignment = TextAlignment.Center;
            fileName.Text = "hello";
            StackPanel content = new StackPanel();
            content.Margin = new Thickness(left1, top1, right1, bottom1);
            content.SetValue(Grid.RowProperty, 0);
            content.Children.Add(fileName);;

您已將TextBlock添加到StackPanel但尚未將StackPanel添加到可視樹。 假設您要將其添加到LayoutRoot ,可以執行此操作

LayoutRoot.Children.Add(content);

附帶說明一下,您是否有理由以編程方式進行此操作? 根據您的情況,使用UserControl可能會更好。

您需要將其添加到諸如StackPanel類的控件中

StackPanel1.Children.Add(fileName);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM