-1

我想用 XAML 代码在控制器中创建一个文本块。有可能这样做吗?还有什么想法吗?

        // Create a string
        String sb = "<TextBlock Name='NameLabel' HorizontalAlignment='Left' TextWrapping='Wrap' FontSize='37.333' FontFamily='Intel Clear Light' Opacity='0.5' Width='277' Grid.Row='4' Grid.ColumnSpan='3' Grid.Column='1' Text='Name (as per IC)' Margin='1,0,0,80' Grid.RowSpan='2'/>";

        // Create a textblock using a XamlReader
        TextBlock myTextBlock = (TextBlock)XamlReader.Load(sb.ToString());

        // Add created button to previously created container.
        splMain.Children.Add(myTextBlock);
4

1 回答 1

0
        I have change my code. And now I have an error of [ splMain.Children.Add(myTextBlock); Additional information: Object reference not set to an instance of an object.]
        // Create a string
        String sb = "<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Text=\"Name (as per IC)\" Margin=\"1,0,0,80\" Grid.RowSpan=\"2\"/>";

        // Create a textblock using a XamlReader
        TextBlock myTextBlock = (TextBlock)XamlReader.Load(sb.ToString());

        // Add created button to previously created container.
        splMain.Children.Add(myTextBlock);
于 2015-10-07T05:16:36.907 回答