简体   繁体   English

在XAML / WPF中创建一个类型/标记

[英]Create a type/tag in XAML/WPF

Here is a part of my XAML in one of my window. 这是我的一个窗口中的XAML的一部分。

 <Border BorderBrush="#a197ff" BorderThickness="1" Margin="5 5" Grid.Row="3">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*" />
                    <ColumnDefinition Width="10*" />
                    <ColumnDefinition Width="1*" />
                </Grid.ColumnDefinitions>

                <Image MaxHeight="64" Source="/GamingClient;component/Assets/next.png" Grid.Column="2"/>
                <Image MaxHeight="64" Source="/GamingClient;component/Assets/prev.png" Grid.Column="0"/>

                <Grid Grid.Column="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="1*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*" />
                        <ColumnDefinition Width="7*" />
                    </Grid.ColumnDefinitions>

                    <Image  MaxHeight="215" MaxWidth="215" HorizontalAlignment="Center" Margin="5 0" Source="/Maps/1.jpg"/>
                    <Grid Grid.Column="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="4*" />
                        </Grid.RowDefinitions>

                        <ComboBox Name="comboBoxMapsName" SelectionChanged="comboBoxMapsName_SelectionChanged" VerticalAlignment="Center" HorizontalAlignment="Left" MaxWidth="200"  Margin="5 0" Grid.Row="0"/>
                        <TextBlock FontStyle="Italic" Foreground="White" Text="Description de la carte par l'auteur qui n'apporte aucune information pertinente aux yeux du joueur ou de son adversaire qui lui est aussi pourri que l'hôte."  TextWrapping="Wrap" Margin="10 5 5 5" Grid.Row="1"/>
                    </Grid>
                </Grid>

            </Grid>
        </Border>

This ''module'' is going to be ''repeated'' elsewhere, caring about good software practices I was wondering if there was any way of ''creating'' a Type/Tag in XAML. 这个“模块”将在其他地方“重复”,关心良好的软件实践我想知道是否有任何方法在XAML中“创建”一个类型/标签。 IE so I could write IE所以我可以写

<CustomXAMLObject><CustomXAMLObject/>

and it would "call" the code I displayed. 它会“调用”我显示的代码。

Furthermore, once I have this "XAML" module, is it possible to pair it with some C# logic so that I get a "View/Controller" package? 此外,一旦我有了这个“XAML”模块,是否可以将它与一些C#逻辑配对,以便获得“视图/控制器”包?

Since I'm always a glutton for easy points, I suppose I'll go ahead and make an actual answer post. 因为我总是贪得无厌,我想我会继续做一个实际的答案。 :) :)

In WPF and other .NET technologies you have the ability to create a templated collection of controls for re-usability and better organization called a UserControl that inherits from ContentControl allowing you to place multiple bits of content into one reference-able control for use throughout your application. 在WPF和其他.NET技术中,您可以创建一个模板化的控件集,用于可重用性和更好的组织,称为UserControl ,它继承自ContentControl,允许您将多个内容放入一个可引用的控件中,以便在整个过程中使用应用。

This way you're not reiterating the same code over and over and when you need to change something you can do so in one centralized place that will reflect globally wherever that control is used. 通过这种方式,您不会反复重复相同的代码,当您需要更改某些内容时,您可以在一个集中的位置执行此操作,无论在何处使用该控件,该地方都会反映出来。

Hope this helps, cheers. 希望这会有所帮助,欢呼。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM