c#字符串加载wpf控件模板代码 - 简书

时间:2024-08-30 09:04:44

原文:c#字符串加载wpf控件模板代码 - 简书

    ResourceManager resManagerA = new ResourceManager("cn.qssq666.Properties.Resources", typeof(cn.ijiami.keyboard.Properties.Resources).Assembly);
string astring = resManagerA.GetString("axml_test");
LogUtil.writeLog("xaml字符串 "+astring);
MemoryStream stream = new MemoryStream(System.Text.Encoding.Default.GetBytes(astring));
DependencyObject element =(DependencyObject) XamlReader.Load(stream);
Button buttonXaml= LogicalTreeHelper.FindLogicalNode(element, "button1") as Button;
DockPanel dockPanel = LogicalTreeHelper.FindLogicalNode(element, "dock_panel") as DockPanel;
<DockPanel
Name="dock_panel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>
<Button Name="button1" Margin="300" Background="#FFD49923">
<Button.Effect>
<DropShadowEffect Color="#FFFF0B0B"/>
</Button.Effect> Hello xaml</Button>
</DockPanel>