Different control based on registered views for this region
I'm building a composite application that, among other things, offers a region for plugins (unity based) to register views for.
The problem is that I want to have a different layout for that region, based on the number of registered views. In particular I want to have a huge (stretched in all directions) single area for the 'one view registered' case and a two column (uniform)grid for the '> 1 view registered' case.
So - for now I'm having (simplified) something like this:
<ItemsControl
rgn开发者_如何学C:RegionManager.RegionName="{x:Static Member=i:RegionNames.MainContentRegion}"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
VerticalAlignment="Stretch" VerticalContentAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentPresenter
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
How can I cover the exceptional 'one element only' case, if the views are ~dynamic~ and registered elsewhere?
You might be able to use a Trigger to change the ItemsPanelTemplate to another panel when Items.Count == 1.
精彩评论