开发者

Different control based on registered views for this region

开发者 https://www.devze.com 2023-04-03 00:35 出处:网络
I\'m building a composite application that, among other things, offers a region for plugins (unity based) to register views for.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消