【问题标题】:C#: Divide XAML-Page in different partsC#:将 XAML 页面划分为不同的部分
【发布时间】:2011-04-04 06:33:17
【问题描述】:

例如,在 Java 中,您可以创建不同的 JPanel 类并将它们放在框架上。

我想做某事。在 C# 中也是如此。

我有一个包含两个相等部分的 XAML 页面。我想将该部分放在不同的“元素”中,并将它们包含在 xaml 页面中。

有可能吗?

【问题讨论】:

    标签: c# xaml


    【解决方案1】:

    您可以在 XAML 中创建用户控件,并且可以将该用户控件放置在页面上的页面容器中。

    请访问这里。能不能帮到你。

    http://www.codeproject.com/KB/WPF/UserControl.aspx

    【讨论】:

      【解决方案2】:

      您实际上必须将应用程序的不同控件放在不同的 userControls 中(在 Visual Studio 中添加新 =>Silverlight UserControl)

      经典的 UserControl XAML 文件如下所示:

      <UserControl xmlns="..." xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:class="MyApp.MyControl" >
        [...]
      </UserControl>
      

      VS 会为你生成 MyApp.MyControl 类。

      然后,在另一个UserControl中,你可以使用MyControl UserControl:

      <UserControl xmlns="..." xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyApp" x:class="MyApp.MyMainControl" >
        [...]
        <local:MyControl />
        [...]
      </UserControl>
      

      这里的本地 xml 命名空间指向同一程序集中的 MyApp .NET 命名空间。事实上,在 xaml 文件中使用的任何控件(例如用户控件)都只是一个类。

      【讨论】:

        猜你喜欢
        • 2011-07-10
        • 1970-01-01
        • 2019-08-30
        • 2014-05-22
        • 1970-01-01
        • 1970-01-01
        • 2016-04-27
        • 2020-11-16
        • 1970-01-01
        相关资源
        最近更新 更多