【问题标题】:Can I share the TreeView control with Silverlight and WPF?我可以与 Silverlight 和 WPF 共享 TreeView 控件吗?
【发布时间】:2010-06-28 14:49:14
【问题描述】:

我想使用 WPF 和 Silverlight 工具包的 TreeView 控件,但让它位于我在 2 个项目之间作为链接共享的同一个 xaml 文件中。在silverlight 中,该类位于System.Windows.Controls.dll 中,而在WPF 中,它位于PresentationFramework.dll 中。因此,对于我的 xaml 命名空间,它们需要以不同方式声明,这会导致问题。有没有办法让这个工作?

【问题讨论】:

    标签: c# .net wpf silverlight treeview


    【解决方案1】:

    AFAIK,您将无法做到这一点,Silverlight 程序集和 .NET 程序集彼此不兼容(尽管 XAML 可能相似,但正如您所注意到的,命名空间是不同的)。

    【讨论】:

      【解决方案2】:

      您是否尝试过使用条件编译符号#if !SILVERLIGHT

      请检查以下链接。
      http://msdn.microsoft.com/en-us/magazine/ee321573.aspx
      What is the best practice for compiling Silverlight and WPF in one project?

      【讨论】:

      • 我实际上是在尝试共享同一个 xaml 文件。不幸的是,在 xaml 中执行 #if !SILVERLIGHT 并不容易。
      • 如果它不是一个复杂的模板,请尝试使用上面提到的条件编译通过后面的代码加载模板。 HTH :)
      【解决方案3】:

      我写了一个blog article 来分享.xaml 文件。这个想法是在您的源代码中创建一个代理控件并在.xaml 中使用该控件:

      namespace UnifiedXaml
      {
          public class MyWrapPanel: WrapPanel { }
      }
      


      <UserControl x:Class="UnifiedXaml.TestControl"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:ux="clr-namespace:UnifiedXaml">
          <ux:MyWrapPanel></ux:MyWrapPanel>
      </UserControl>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多