WPF:如何处理多XAML UI? [英] WPF: How to handle multi-XAML UIs?

查看:168
本文介绍了WPF:如何处理多XAML UI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道你们是谁,但我患有深度压痕过敏的严重病例。我几乎不能管理所有这些缩进的XAML块。



我目前的应用程序是基于一个具有多种花哨功能的大型DataGrid(更多的来了),但我想要添加几个选项卡在屏幕顶部,以便有一个额外的,第二个非常相似的DataGrid。



我想实现它如下:

 < Tab> 
< Tab Selection 1>
<其他XAML文件中的DataGrid 1>
< / Tab选择1>
< Tab Selection 2>
<其他XAML文件中的DataGrid 2>
< / Tab选择2>
< Tab>

所以,我会有一个小的XAML文件,它控制2个更大的XAML文件。



这应该是可行的吗?



可以一个善良的灵魂提供细节吗?



TIA。

解决方案

只需,如下所示:

 < Window .... 
xmlns:local =clr-namespace:MyApp>

< TabControl>
< TabItem>
< local:MyUserControl />
< / TabItem>
< / TabControl>
< / Window>


I don't know about you folks, but I suffer from a severe case of Deep Indentation Allergy. I can barely manage all those indented XAML blocks.

My current application is based on a large DataGrid with of kinds of fancy features (with more to come) but I would like to add a couple a tabs on top of the screen in order to have an additional, second very similar DataGrid.

I would like to implement it as follow:

<Tab>
    <Tab Selection 1>
        <DataGrid 1 in some other XAML file>
    </Tab Selection 1>
    <Tab Selection 2>
        <DataGrid 2 in some other XAML file>
    </Tab Selection 2>
<Tab>

So, I would have a small XAML file which controls 2 much bigger XAML files.

That should be doable, right?

Can a kind soul provide the details?

TIA.

解决方案

Simply create a new UserControl:

1 - Right Click your Project in Solution Explorer, select Add -> New Item:

2 - Select WPF UserControl:

3: Create your DataGrid inside the UserControl:

<UserControl x:Class="MyApp.MyUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <DataGrid>
      <!-- lots of XAML ... -->
   </DataGrid>
</UserControl>

4: Put the UserControl inside the TabItem:

You will need to Import your Namespace, like so:

<Window ....
        xmlns:local="clr-namespace:MyApp">

    <TabControl>
      <TabItem>
         <local:MyUserControl/>
      </TabItem>
    </TabControl>
</Window>

这篇关于WPF:如何处理多XAML UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆