C# 我需要从每个元素中消除xmlns属性

C# 我需要从每个元素中消除xmlns属性,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,我不想把xmlns属性放在我要添加到网格中的每个元素中。 是否有全局性的定义 这是我的代码: string xaml = "<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Name='canvasGrid'> <Ellipse xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' /

我不想把xmlns属性放在我要添加到网格中的每个元素中。 是否有全局性的定义

这是我的代码:

 string xaml = "<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'  
     Name='canvasGrid'>
    <Ellipse xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' />
      <Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' /> 
   </Grid>"

 Grid grid = (Grid)XamlReader.Load(xaml);
 panel.Children.Add(grid);
string xaml=”
"
Grid Grid=(Grid)XamlReader.Load(xaml);
panel.Children.Add(网格);

是的,你不需要为每个控件都设置它<根元素(网格)上的代码>设置足够了。

xmlns在主窗口中定义。无法使用窗口标记编写窗口布局。

什么异常?发布它。是的,它现在可以工作了……我想我尝试了根元素和其他一些有xmlns标记的元素。@TaLhaKhan-太棒了。。!!