views:

155

answers:

1

Hi, I have the following defined in my control:

<Style TargetType="primitives:CalendarDayButton" x:Key="EventCalendarDayButton">
        <Setter Property="Background" Value="#FFBADDE9"/>
        <Setter Property="MinWidth" Value="5"/>
        <Setter Property="MinHeight" Value="5"/>
        <Setter Property="FontSize">
            <Setter.Value>
                <Binding Path="DayFontSize">
                    <Binding.RelativeSource>
                        <RelativeSource Mode="FindAncestor" AncestorType="{x:Type toolkit:Calendar}" />
                    </Binding.RelativeSource>
                </Binding>
            </Setter.Value>
        </Setter>
        <Setter Property="HorizontalContentAlignment" Value="Right"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="primitives:CalendarDayButton">
                    <Grid MouseDown="Grid_MouseDown">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="18" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>                         
                        <Rectangle x:Name="SelectedBackground" Grid.Row="1" RadiusX="1" RadiusY="1" Opacity="0" Fill="{TemplateBinding Background}"/>
                        <Rectangle x:Name="Background" Grid.Row="1" RadiusX="1" RadiusY="1" Opacity="0" Fill="{TemplateBinding Background}" />
                        <Rectangle x:Name="InactiveBackground" Grid.Row="1" RadiusX="1" RadiusY="1" Opacity="0" Fill="#FFA5BFE1"/>
                        <Border>
                            <Border.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStop x:Name="StartGradient" Color="#FFD5E2F2" Offset="0"/>
                                    <GradientStop x:Name="EndGradient" Color="#FFB9C9DD" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                            <ContentPresenter x:Name="NormalText" Margin="5,1,5,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                <TextElement.Foreground>
                                    <SolidColorBrush x:Name="selectedText" Color="#FF333333" />
                                </TextElement.Foreground>
                            </ContentPresenter>
                        </Border>
                        <Rectangle x:Name="Border" StrokeThickness="0.5" Grid.RowSpan="2" SnapsToDevicePixels="True">
                            <Rectangle.Stroke>
                                <SolidColorBrush x:Name="BorderBrush" Color="#FF5D8CC9"/>
                            </Rectangle.Stroke>
                        </Rectangle>
                        <Path x:Name="Blackout" Grid.Row="1" Opacity="0" Margin="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" Fill="#FF000000" Stretch="Fill" Data="M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633,11.029181 L15.191895,11.029181 L12.844727,13.999395 L15.21875,17.060919 L12.962891,17.060919 L11.673828,15.256231 L10.352539,17.060919 L8.1396484,17.060919 L10.519043,14.042364 z"/>
                        <Rectangle Width="0" x:Name="DayButtonFocusVisual" Grid.Row="1" Visibility="Collapsed" IsHitTestVisible="false" RadiusX="1" RadiusY="1" Stroke="#FF45D6FA"/>                            
                        <Button x:Name="ActivateDayViewOnDay" Grid.Row="0" Opacity="0.3" Height="15" Margin="1,1,1,1" PreviewMouseLeftButtonDown="DayView_Click" />                          
                        <ScrollViewer Grid.Row="1" >
                            <ScrollViewer.Content>                          
                            <local:TestListBox
                            x:Name="eventsLbx" 
                            Background="Transparent"
                            BorderBrush="Transparent"
                            >
                            <local:TestListBox.ItemsSource>
                                <MultiBinding Converter="{StaticResource calendarEventsConverter}">
                                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type local:EventCalendar}}" Path="CalendarEvents"/>
                                    <Binding RelativeSource="{RelativeSource Mode=Self}" Path="DataContext"/>
                                </MultiBinding>
                            </local:TestListBox.ItemsSource>
                            <local:TestListBox.ItemTemplate>
                                <DataTemplate>                              
                                        <TextBlock TextTrimming="CharacterEllipsis" HorizontalAlignment="Center" FontSize="12" Text="{Binding Text}" />                             
                                </DataTemplate>
                            </local:TestListBox.ItemTemplate>
                        </local:TestListBox>   
                           </ScrollViewer.Content>
                        </ScrollViewer>
                    </Grid>                            
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="eventsLbx" Property="HasItems" Value="False">
                            <Setter TargetName="eventsLbx" Property="Visibility" Value="Hidden"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Now if there are more items than are visible, then the scrollviewer appears properly but the user CANNOT drag the scrollviewer middle button for scrolling.

The user can click on the arrows at the end of the scrollviewer to scroll but he cannot click the bar that appears on the scrollbar and drag it to actually scroll the contents.

I cannot figure out why this is happening...

A: 

If you want to scroll the items in your ListBox, you do not need to wrap it in a ScrollViewer. The ListBox natively supports scrolling. That means, if your ListBox is too small to display all its items, it automatically adds ScrollBars to the side.

gehho
Ive tried it without excplictly adding the scrollbar....it still does not behave correctly...I cannot drag the bar to scroll the items.
guest
So how do you restrict the size of the ListBox? Do you set fixed Width and Height properties? Do you use it in a Grid or in a StackPanel? Please update your code above, so that everything is visible and not completely messed up. Please also include the surrounding elements (the Panel that the ListBox is embedded in).
gehho
Hi gehho, Thanks for being patient, I just edited my post to include the whole style. I am basically using the wpf calendar control from microsoft and modifying it http://msdn.microsoft.com/en-us/magazine/dd882520.aspx
guest
Hmmm, cannot find any problems in there. Did you also adjust the `ControlTemplate` for the `ScrollBar` or `ScrollViewer`?
gehho
No i did not adjust it.
guest