views:

264

answers:

0

For an application I'm developing, I have a few nested ItemsControls that are used in the following layout some irrelevant items left out for brevity:

ItemsControl (GroupItemsControl) - ItemPanel: StackPanel with vertical orientation - ItemTemplate: ScrollViewer with an ItemsControl (SliceItemsControl) inside - ItemPanel: Canvas* - ItemTemplate: Canvas containing an ItemsControl (EventItemsControl) - ItemPanel: Custom Panel that will end up with a set height after Measure/Layout - ItemTemplat: StackPanel containing rectangle and textblock, horizontally oriented

The issue is that I need the Canvas marked with "*" to be sized to the height of the custom panel that is nested two layers deep (And actually it would need to be the height of the tallest SliceItemsControl Item (the custom panel height) contained within it.) The objective is that the scrollviewer could scroll left/right but the height of the scrollviewer would adjust so that there is no vertical scrolling necessary.

Note that I am trying to use MVVM (my first time) so I'm trying to stick with as much data binding to a ViewModel as possible.

Full xaml for the layout:

<navigation:Page.Resources>
     <SPARTA_ViewModel:FlexCalendar x:Key="FlexCalendarDataSource" d:IsDataSource="True"/>
     <SPARTA_HelperClasses:DateToOffsetConverter x:Key="DateOffsetConverter"/>
     <SPARTA_HelperClasses:DaysToPixelsConverter x:Key="DatePixelConverter"/>
     <ItemsPanelTemplate x:Key="GroupsItemPanel">
      <StackPanel/>
     </ItemsPanelTemplate>
     <ItemsPanelTemplate x:Key="SlicesPanelTemplate">
      <Canvas />
     </ItemsPanelTemplate>
    <ItemsPanelTemplate x:Key="EventsPanelTemplate">
        <SPARTA_HelperClasses:FlexCalendarEventPanel x:Name="EventPanel" SizeChanged="EventPanel_SizeChanged" />
    </ItemsPanelTemplate>
    <DataTemplate x:Key="EventsItemTemplate">
        <StackPanel Orientation="Horizontal"
                    >
            <Rectangle Fill="Green" Width="{Binding Length}" Height="20">
                <ToolTipService.ToolTip>
                    <TextBlock Text="{Binding StartDate}"></TextBlock>
                </ToolTipService.ToolTip>
            </Rectangle>
            <TextBlock Text="{Binding EventName}"></TextBlock>
        </StackPanel>
    </DataTemplate>
     <DataTemplate x:Key="SlicesItemTemplate">
      <Canvas Width="{Binding Path=SliceSize, Source={StaticResource FlexCalendarDataSource}, Converter={StaticResource DatePixelConverter}, ConverterParameter={StaticResource FlexCalendarDataSource}}" 
                Height="300" 
                Background="#FF700505" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Top" 
                Canvas.Left="{Binding Left}" 
                x:Name="EventAreaCanvas">
            <ToolTipService.ToolTip>
                <TextBlock Text="{Binding SliceRange.StartDate}"></TextBlock>
            </ToolTipService.ToolTip>
            <SPARTA_HelperClasses:EventsItemsCollection x:Name="EventsItemsControl" ItemsSource="{Binding Events, Mode=OneWay}" ItemsPanel="{StaticResource EventsPanelTemplate}" ItemTemplate="{StaticResource EventsItemTemplate}"/>
      </Canvas>
     </DataTemplate>
     <DataTemplate x:Key="GroupsItemTemplate">
      <StackPanel Orientation="Horizontal" Margin="5">
       <Border Width="{Binding GroupColWidth, Mode=OneWay, Source={StaticResource FlexCalendarDataSource}}" BorderBrush="Black" BorderThickness="1" MinHeight="50" CornerRadius="3" Background="#FF629433">
        <TextBlock Text="{Binding Title, Mode=OneWay}" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center"/>
       </Border>
       <ScrollViewer MinHeight="50" 
                          HorizontalContentAlignment="Left" 
                          VerticalContentAlignment="Top" 
                          Padding="1" 
                          VerticalScrollBarVisibility="Auto" 
                          Width="750" 
                           >
      <SPARTA_HelperClasses:SliceItemsCollection 
                    x:Name="SlicesItemsControl" 
                    ItemsSource="{Binding Slices, Mode=OneWay}" 
                    ItemsPanel="{StaticResource SlicesPanelTemplate}" 
                    ItemTemplate="{StaticResource SlicesItemTemplate}"
                    Height="500"/>

       </ScrollViewer>
      </StackPanel>
     </DataTemplate>
    </navigation:Page.Resources>
<Grid x:Name="LayoutRoot" Height="768" Margin="0" Width="1024" DataContext="{Binding Source={StaticResource FlexCalendarDataSource}}" VerticalAlignment="Top">

    <Grid.RowDefinitions>
     <RowDefinition Height="45"/>
     <RowDefinition />
     <RowDefinition Height="48"/>
    </Grid.RowDefinitions>
    <ItemsControl x:Name="GroupsItemsControl" 
                  Margin="0" 
                  Grid.Row="1" 
                  DataContext="{StaticResource FlexCalendarDataSource}" 
                  ItemsSource="{Binding Groups, Mode=OneWay}" 
                  ItemsPanel="{StaticResource GroupsItemPanel}" 
                  ItemTemplate="{StaticResource GroupsItemTemplate}" 
                  HorizontalContentAlignment="Left" 
                  VerticalContentAlignment="Top">

    </ItemsControl>
    <TextBlock Margin="0" Text="{Binding Title, Mode=OneWay}" TextWrapping="Wrap" d:LayoutOverrides="Height" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" TextDecorations="Underline" FontSize="24"/>
    <Button x:Name="btnLoad" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Content="Load Data"/>
    <TextBlock x:Name="txtVisibleDate" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75" Text="{Binding VisibleDate}"/>
</Grid>