Question

I've re-styled a SurfaceScrollViewer but it appears to throw a NullPointerException whenever I double-click the track area.. by the looks of the exception, I believe it has to do with the CommandBinding being null.

A first chance exception of type 'System.NullReferenceException' occurred in Microsoft.Surface.Presentation.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>Sendx.Cabo.Analyzer.Application.exe</AppDomain><Exception><ExceptionType>System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Object reference not set to an instance of an object.</Message><StackTrace>   at Microsoft.Surface.Presentation.Controls.SurfaceScrollViewer.OnScrollPage(OrientationFlags orientation, Boolean isIncrease)
   at Microsoft.Surface.Presentation.Controls.SurfaceScrollViewer.OnScrollPageDownCommand(Object target, ExecutedRoutedEventArgs args)
   at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
   at System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding)
   at System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   at System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e) ...

Here's the main part of the style. Is there some template binding that I am missing that is causing this issue?

<Style x:Key="ScrollViewerStyle" TargetType="{x:Type controls:SurfaceScrollViewer}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                <Grid x:Name="Grid" Background="{TemplateBinding Background}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Rectangle x:Name="Corner" Grid.Column="1" Fill="{x:Null}" Grid.Row="1"/>
                    <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" 
                                            CanContentScroll="{TemplateBinding CanContentScroll}"   
                                            CanHorizontallyScroll="False" 
                                            CanVerticallyScroll="False"   
                                            ContentTemplate="{TemplateBinding ContentTemplate}"   
                                            Content="{TemplateBinding Content}" Grid.Column="0"   
                                            Margin="{TemplateBinding Padding}" 
                                            Grid.Row="0"
                                            OverridesDefaultStyle="True"/>
                    <ScrollBar x:Name="PART_VerticalScrollBar" 
                               Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"   
                               AutomationProperties.AutomationId="VerticalScrollBar" 
                               Cursor="Arrow" 
                               Grid.Column="1"   
                               Maximum="{TemplateBinding ScrollableHeight}"
                               Minimum="0" 
                               Grid.Row="0"   
                               Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"   
                               ViewportSize="{TemplateBinding ViewportHeight}" 
                               Style="{DynamicResource VerticalScrollStyle}"   
                               Background="{x:Null}" Width="Auto" Margin="0"/>
                    <ScrollBar x:Name="PART_HorizontalScrollBar" 
                               Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"   
                               AutomationProperties.AutomationId="HorizontalScrollBar" 
                               Cursor="Arrow" 
                               Grid.Column="0"   
                               Maximum="{TemplateBinding ScrollableWidth}" 
                               Minimum="0" 
                               Orientation="Horizontal" 
                               Grid.Row="1"   
                               Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"   
                               ViewportSize="{TemplateBinding ViewportWidth}" 
                               Style="{DynamicResource HorizontalScrollStyle}"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Was it helpful?

Solution

Issue was fixed by using a SurfaceScrollBar within the SurfaceScrollView style instead of a standard ScrollBar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top