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.
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.
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. 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.
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>
<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.
Any pointers would be much appreciated!
我最终制作了一个TabControl,可以按需注册选项卡(例如,通过RegisterTab
方法),而不是尝试通过XAML对其进行定义。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.