简体   繁体   English

WPF窗口/用户控件继承XAML

[英]WPF window/usercontrol inheritance XAML

I'm implementing an editor for a game and ran across a slight inconvience I can't seem to figure out. 我正在为游戏实现编辑器,遇到了我似乎无法弄清的一点不便之处。 My Google-fu is also failing on me to find an answer whether or not what I want is even possible. 我的Google-fu还是无法找到答案,无论我想要的东西是否可行。

My editor basically has a detail-window for each object it manages, this detail window is always the same: a tab-control, with on Tab called "Properties", and 1 or more tabs specific to the object the window is for. 我的编辑器基本上为它管理的每个对象都有一个详细信息窗口,此详细信息窗口始终是相同的:一个选项卡控件,在选项卡上带有一个名为“属性”的标签,以及一个或多个特定于该窗口对象的选项卡。

I figured it would be nice to have a BaseEditor.xaml which has the TabControl with the Properties-tab defined, from which you can extend and add more tabs as you please. 我认为拥有BaseEditor.xaml会很好,它具有定义了Properties-tab的TabControl,您可以根据需要扩展和添加更多标签。

I've tried multiple solution, one by making a UserControl, adding a TabControl on it, then add a CompositeCollection to it, which is bound to a property in the code-behind, which I can then technically modify when I add the usercontrol to a window. 我尝试了多种解决方案,一种方法是制作一个UserControl,在其上添加一个TabControl,然后向其添加一个CompositeCollection,该绑定到后面的代码中的一个属性上,当我将usercontrol添加到一个窗口。 However, it doesn't work in the slightest, and I'm also not happy with the fact I have to add the UserControl to a Window, rather than extend from a Window. 但是,它一点也不起作用,而且我对必须将UserControl添加到Window而不是从Window扩展的事实也感到不满意。

All in all, here's my first attempt: 总而言之,这是我的第一次尝试:

<UserControl>
    <Grid>
        <TabControl HorizontalAlignment="Left" Height="300" VerticalAlignment="Top" Width="300">
            <TabControl.ItemsSource>
                <CompositeCollection>
                    <CollectionContainer Collection="{Binding TabItems}" />
                    <TabItem Header="Properties" />
                </CompositeCollection>
            </TabControl.ItemsSource>
        </TabControl>
    </Grid>
</UserControl>

Then on the Window it's used like this: 然后在Window上这样使用:

<Window>
    <Grid>
        <UserControl>
            <UserControl.TabItems>
                <TabItem Header="Test" />
            <UserControl.TabItems>
        </UserControl>
    </Grid>
</Window>

This is pseudo-code, but as said, it doesn't work, it will just show the properties-tab and that's it. 这是伪代码,但是如前所述,它不起作用,它将仅显示properties-tab。

Any pointers would be much appreciated! 任何指针将不胜感激!

我最终制作了一个TabControl,可以按需注册选项卡(例如,通过RegisterTab方法),而不是尝试通过XAML对其进行定义。

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

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