C# 在WPF中获取XAML代码
如何将窗口的XAML代码作为字符串获取、更改此字符串并将此字符串作为窗口的XAML代码上载 例如,我有C# 在WPF中获取XAML代码,c#,wpf,xaml,C#,Wpf,Xaml,如何将窗口的XAML代码作为字符串获取、更改此字符串并将此字符串作为窗口的XAML代码上载 例如,我有 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox Margin="0,0,9,38" Name="button1" Height="82" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="132"></ComboBox>
</Grid>
</Window>
我希望最终得到这个xaml代码
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox Margin="0,0,9,38" Name="button1" Height="82" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="132">
<ComboBox.ItemTemplate>
<DataTemplate>
<local:d_dddw_imp_insurance_list />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</Window>
如果将wpf/xaml与c#一起使用,visual studio通常会将xaml代码编译为c#,以尽可能提高性能。如果您想拥有一些动态XAML,您需要使用
XamlReader
来读取XAML并显示在“您自己的”位置
请看一下:
您可以非常轻松地更改或操作xaml并显示结果。如果将wpf/xaml与c#一起使用,visual studio通常会将xaml代码编译为c#,以尽可能提高性能。如果您想拥有一些动态XAML,您需要使用
XamlReader
来读取XAML并显示在“您自己的”位置
请看一下:
您可以非常轻松地更改或操作xaml并显示结果。非常确定Windows的xaml不可用,因为它已编译。如果您想更改窗口,只需使用WPFAPI即可。不需要在运行时摆弄XAML上传是什么意思?更改运行时的显示方式并不是通过将XAML修改为文本来完成的。您真正想要实现什么?非常确定Windows的XAML不可用,因为它被编译了。如果您想更改窗口,只需使用WPFAPI即可。不需要在运行时摆弄XAML上传是什么意思?更改运行时的显示方式并不是通过将XAML修改为文本来完成的。你真正想要实现什么?