0
votes

I have searched all over, and even though everyone seems to be having this problem, I can't find the fix for my specific problem..

Here's the problem. I want to make a custom Calendar Control. In order to do this I am filling an ItemsControl with TextBlocks, and then putting a scrollviewer around it.

But for some reason the scrollviewer scrollbar seems disabled, and it doesn't seem to recognize that it's filled with data.

Here's my Code

                   <Grid>          
                       <ScrollViewer>
                            <ItemsControl ItemsSource="{Binding CalendarDates}" Height="75">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate DataType="local:Calender">
                                            <TextBlock Name="CalendarDate" FontSize="12" Text="{Binding}" TextAlignment="Right" VerticalAlignment="Top" Height="Auto"/>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <UniformGrid Rows="1" Columns="7"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                        </ScrollViewer>
                    </Grid>

And here's my MainWindow.xaml where I initialize it

    <Grid>
    <!--Row Definitins -->
    <Grid.RowDefinitions>
        <RowDefinition Height = "Auto"/>
        <RowDefinition Height = "*"/>
        <RowDefinition Height = "Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"/>
        <ColumnDefinition Width="25*"/>
        <ColumnDefinition Width="10*"/>
    </Grid.ColumnDefinitions>

<localControl:Calender Grid.Column="1" Grid.Row="1"/>

</Grid>

The code fills the scrollviewer just fine, but like I said above the scrollbar seems disabled, and even when I hard code the size it still doesn't work!

Also I have already tried to set the SccrollViewer.VerticalScrollBar= Visible, and the height of the scrollviewer, as well as over a dozen of the "fixes" here on Stack Overflow, but none of them work in my case

1
"the scrollbar" is the horizontal scrollbar?Clemens
No, the vertical scrollbar on the Scrollviewer. And it is visible, it just doesn't seem to be working with the data I put in. Trust me I've checked all your questions on this, and this isn't a duplicate of any of them.Jeff Klein

1 Answers

1
votes

I found the answer... The ItemsControl template itself does not allow for a scrollviewer.

I found the answer in this magazine on page 38.

https://dncmagazine.blob.core.windows.net/edition20/DNCMag-Issue20.pdf

We need to modify the ItemsControl template as follows:

 <ItemsControl.Template>  
 <ControlTemplate TargetType=  "ItemsControl">    
 <ScrollViewer>      
 <ItemsPresenter/>    
 </ScrollViewer>  
 </ControlTemplate>
 </ItemsControl.Template>