Repeat the same structure XAML several times

0

I have this structure ...

    <StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="4*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                        <CheckBox Grid.Column="0" Margin="4" Content="Potencia  4 Polos"/>
                        <TextBox Grid.Column="1"/>
                        <TextBlock Grid.Column="2" Text="0" Background="#eee"/>
                        <TextBlock Grid.Column="3" Text="0" Background="#eee"/>
               </Grid>
    </StackPanel>

Can I somehow repeat the code several times on top of each other without repeating it? Creating a template or similar way

    
asked by Edulon 23.12.2017 в 12:36
source

1 answer

0

Create a control and add the code. So when you want to reuse it, you just have to import your control using the xmlns attribute:

<UserControl x:Class="SO_app.ForAsperger"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         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:vm="clr-namespace:VM;assembly=VM"//this is where we define reference to our ViewModel
         xmlns:model="clr-namespace:Model;assembly=Model"//this is where we define our model object so we know the structure for our DataTemplate
         mc:Ignorable="d" 

         xmlns:miControl="namespace.deTu.Control">

         <miControl:NombreDelControl></miControl:NombreDelControl>

</UserControl>

xmlns:miControl="" is where you must include the namespace where your control is located.

    
answered by 25.12.2017 в 14:10