日期:2014-05-18  浏览次数:20769 次

C#操作导出xml的问题
我在WPF中导出控件的XAML代码,用的是XElement元素,现在的问题是导出的xaml里,根元素除外,其它的节点,只要不是叶子节点,或者说只要节点里面还包含了其它的节点,都会多出来一个xmlns="",不知道什么原因,求指教。

XML code
<UserControl xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <Grid Width="147.00000000000003" Background="#FF808080" Height="200.00000000000003" xmlns="">
    <Button Canvas.Left="27" Canvas.Top="54" Panel.ZIndex="1" Width="65" Height="65" Content="按钮" />
  </Grid>
</UserControl>


Grid的属性里,多了一个xmlns="",有人知道它是怎么生成的吗,怎么去掉?

如果Button下面也有子元素,那么Button的属性也会出来这个东西。


------解决方案--------------------
new XElement(ns+"Grid")的时候,ns定义成 http://schemas.microsoft.com/winfx/2006/xaml/presentation