0

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...

1
  • Please edit your posted code, so that everything is displayed. It seems like the first lines have been "swallowed". Most probably because your indentation was not right. Commented May 11, 2010 at 15:22

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Ive tried it without excplictly adding the scrollbar....it still does not behave correctly...I cannot drag the bar to scroll the items.
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).
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 msdn.microsoft.com/en-us/magazine/dd882520.aspx
Hmmm, cannot find any problems in there. Did you also adjust the ControlTemplate for the ScrollBar or ScrollViewer?
0

Your ScrollViewer and ListBox are inside a Grid, and you have some code behind the MouseDown event of that Grid.

<Grid MouseDown="Grid_MouseDown">

Something you're doing in that method may be getting in the way of the mouse mechanisms of the ScrollViewer, disrupting event bubbling or something like that.

Check your code-behind, or post it here so we can help you with it :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.