WPF: How to handle multi-XAML UIs?

前端 未结 1 1925
北恋
北恋 2021-01-27 11:32

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 appli

相关标签:
1条回答
  • 2021-01-27 12:16

    Simply create a new UserControl:

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

    enter image description here

    2 - Select WPF UserControl:

    enter image description here

    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>
    
    0 讨论(0)
提交回复
热议问题