在c#中动态添加文本块

时间:2015-10-07 05:36:46

标签: c# xamlreader

我的下面代码抛出空引用异常

enter image description here

    // 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);

0 个答案:

没有答案