Region not available

Dec 8, 2008 at 6:12 AM
Hi, I'm wondering if the Composite team have a suggestion as to how to solve the following.

I have a panel that displays some data for our project. If the data is empty it shows one template. If not then it shows a template with a region in it. Then other modules can add their relevant views to the region.

The XAML looks like this:

        <Control>
            <Control.Resources>
                <ControlTemplate x:Key="open">
                    <ItemsControl cal:RegionManager.RegionName="stack">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>

                </ControlTemplate>
                <ControlTemplate x:Key="closed">
                    <TextBlock Foreground="White">No Data.</TextBlock>
                </ControlTemplate>
            </Control.Resources>

            <Control.Style>
                <Style TargetType="{x:Type Control}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=Data, Converter={StaticResource isNull}}" Value="True">
                            <Setter Property="Template" Value="{StaticResource closed}"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Data, Converter={StaticResource isNull}}" Value="False">
                            <Setter Property="Template" Value="{StaticResource open}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Control.Style>
        </Control>

The problem I have is that the default state is "closed" so the other modules don't initialize properly because the region is not visible and is not part of the list of regions.

Any suggestions for how to get around this?

Thanks
Cameron MacFarland
Dec 8, 2008 at 6:45 AM
What about putting the ItemControl in Item template and show/hide that control from trigger?

For example:  Note that it's just a concept. The syntax might not be correct. The main idea is that put the itemcontrol in template and show/hide it from tigger. Hope it helps.

<Control.Style>
             <Style TargetType="{x:Type Control}">
            <Setter Property="Template">
                <Setter.Value>
                       <ControlTemplate TargetType="{x:Type Control}">
<ItemsControl x:Name="myItemControl" cal:RegionManager.RegionName="stack">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
<TextBlock x:Name="myTextblock" Foreground="White">No Data.</TextBlock>
    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=Data, Converter={StaticResource isNull}}" Value="True">
                            <Setter Property="Visibility" TargetSource="myTextBlock" Value="Visibile"/>
                            <Setter Property="Visibility" TargetSource="myItemControl" Value="Hidden"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Data, Converter={StaticResource isNull}}" Value="False">
                            <Setter Property="Visibility" TargetSource="myTextBlock" Value="Hidden"/>
                            <Setter Property="Visibility" TargetSource="myItemControl" Value="Visible"/>
                        </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>


Dec 8, 2008 at 7:46 AM
Yep that worked. The syntax was bad but I got what you meant.

For reference, here's the syntax that worked.I had to put the two controls in a panel to have them show up.

    <Grid>
        <ItemsControl cal:RegionManager.RegionName="stack" x:Name="stackPanel">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>

            <ItemsControl.Style>
                <Style TargetType="{x:Type ItemsControl}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=Data, Converter={StaticResource isNull}}" Value="True">
                            <Setter Property="UIElement.Visibility" Value="Hidden"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ItemsControl.Style>
        </ItemsControl>

        <TextBlock x:Name="textBlock" Foreground="White" Text="No Data.">
            <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=Data, Converter={StaticResource isNull}}" Value="False">
                            <Setter Property="UIElement.Visibility" Value="Hidden"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
    </Grid>