PullToRefreshListView icon indicating copy to clipboard operation
PullToRefreshListView copied to clipboard

Delegate to an instance method cannot have null 'this'

Open arsenium opened this issue 10 years ago • 5 comments

What am I doing wrong? I have a mistake: Delegate to an instance method cannot have null 'this'. http://i.imgur.com/wosgusv.png http://i.imgur.com/zWkILsv.png My app for Windows Phone 8.1 only. I use Deani Hansen's Pull-to-Refresh ScrollViewer, but the same error with PullToRefreshListView. http://i.imgur.com/nBGYZqp.png http://i.imgur.com/xiH8q3Q.png http://i.imgur.com/OUrezgv.png

arsenium avatar Jan 30 '16 08:01 arsenium

Something goes wrong in the OnApplyTemplate method. Can you double check that the style template is in your project (Themes\Generic.xaml - name and path is important) ? I assume that this is your problem.

XamlBrewer avatar Jan 30 '16 12:01 XamlBrewer

in my solution added Class Library Controllers with PullToRefreshListView class and Themes\Generic.xaml file. http://i.imgur.com/yXZ014K.png

Generic.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="using:Controllers.Controls"
    mc:Ignorable="d">
    <Style TargetType="controls:PullToRefreshScrollViewer">
        <Setter
            Property="VerticalAlignment"
            Value="Stretch" />
        <Setter
            Property="HorizontalAlignment"
            Value="Stretch" />
        <Setter
            Property="Foreground"
            Value="Black" />
        <Setter
            Property="Template">
            <Setter.Value>
                <ControlTemplate
                    TargetType="controls:PullToRefreshScrollViewer">
                    <Grid
                        x:Name="ContainerGrid">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup
                                x:Name="VisualStateGroup">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition
                                        GeneratedDuration="0:0:0.2"
                                        To="ReadyToRefresh" />
                                </VisualStateGroup.Transitions>
                                <VisualState
                                    x:Name="Normal" />
                                <VisualState
                                    x:Name="ReadyToRefresh">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="(UIElement.Visibility)"
                                            Storyboard.TargetName="TextPull">
                                            <DiscreteObjectKeyFrame
                                                KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="(UIElement.Visibility)"
                                            Storyboard.TargetName="TextRefresh">
                                            <DiscreteObjectKeyFrame
                                                KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation
                                            Duration="0"
                                            To="0.5"
                                            Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)"
                                            Storyboard.TargetName="Arrow"
                                            d:IsOptimized="True" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ScrollViewer
                            Margin="0,0,0,-100"
                            x:Name="ScrollViewer"
                            RenderTransformOrigin="0.5,0.5">
                            <ScrollViewer.RenderTransform>
                                <CompositeTransform
                                    TranslateY="-100" />
                            </ScrollViewer.RenderTransform>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition
                                        Height="auto" />
                                    <RowDefinition
                                        Height="*" />
                                </Grid.RowDefinitions>
                                <Border
                                    Height="{TemplateBinding RefreshHeaderHeight}"
                                    x:Name="PullToRefreshIndicator"
                                    Background="Transparent">
                                    <Grid
                                        HorizontalAlignment="Center">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition
                                                Width="auto" />
                                            <ColumnDefinition
                                                Width="auto" />
                                        </Grid.ColumnDefinitions>
                                        <Grid
                                            Width="40">
                                            <Viewbox
                                                x:Name="Arrow"
                                                Height="15"
                                                VerticalAlignment="Top"
                                                Margin="0,4,0,0"
                                                RenderTransformOrigin="0.5,0.5">
                                                <Viewbox.RenderTransform>
                                                    <CompositeTransform
                                                        Rotation="180" />
                                                </Viewbox.RenderTransform>
                                                <Path
                                                    Width="12"
                                                    Height="12.9999"
                                                    Stretch="Fill"
                                                    Fill="{TemplateBinding ArrowColor}"
                                                    Data="M 20.4289,10.4376L 25,15.0087L 23.571,16.4376L 20.0291,12.8957L 20.0291,21.9999L 18.0083,21.9999L 18.0083,12.8583L 14.4289,16.4377L 13,15.0087L 17.5624,10.429L 19.0087,9" />
                                            </Viewbox>
                                        </Grid>
                                        <TextBlock
                                            Grid.Column="1"
                                            Foreground="{TemplateBinding Foreground}"
                                             FontSize="20"
                                            x:Name="TextPull"
                                            Text="{TemplateBinding PullText}" />
                                        <TextBlock
                                            Foreground="{TemplateBinding Foreground}"
                                            FontSize="20"
                                            x:Name="TextRefresh"
                                            Visibility="Collapsed"
                                            Text="{TemplateBinding RefreshText}"
                                            Grid.Column="1" />
                                    </Grid>
                                </Border>
                                <ContentPresenter
                                    Content="{TemplateBinding Content}"
                                    Grid.Row="1" />
                            </Grid>
                        </ScrollViewer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="controls:PullToRefreshListView">
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="TabNavigation"
                Value="Once" />
        <Setter Property="IsSwipeEnabled"
                Value="True" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Disabled" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollMode"
                Value="Disabled" />
        <Setter Property="ScrollViewer.IsHorizontalRailEnabled"
                Value="False" />
        <Setter Property="ScrollViewer.VerticalScrollMode"
                Value="Enabled" />
        <Setter Property="ScrollViewer.IsVerticalRailEnabled"
                Value="False" />
        <Setter Property="ScrollViewer.ZoomMode"
                Value="Disabled" />
        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled"
                Value="False" />
        <Setter Property="ScrollViewer.BringIntoViewOnFocusChange"
                Value="True" />
        <Setter Property="VerticalAlignment"
                Value="Stretch" />
        <Setter Property="HorizontalAlignment"
                Value="Stretch" />
        <Setter Property="Foreground"
                Value="Black" />
        <Setter Property="ItemContainerTransitions">
            <Setter.Value>
                <TransitionCollection>
                    <AddDeleteThemeTransition />
                    <ContentThemeTransition />
                    <ReorderThemeTransition />
                    <EntranceThemeTransition IsStaggeringEnabled="False" />
                </TransitionCollection>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <ItemsStackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:PullToRefreshListView">
                    <Grid x:Name="ContainerGrid">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="VisualStateGroup">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.2"
                                                      To="ReadyToRefresh" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="ReadyToRefresh">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="TextPull">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="TextRefresh">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Duration="0"
                                                         To="0.5"
                                                         Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)"
                                                         Storyboard.TargetName="Arrow"
                                                         d:IsOptimized="True" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ScrollViewer Margin="0"
                                          x:Name="ScrollViewer"
                                          TabNavigation="{TemplateBinding TabNavigation}"
                                          HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                          HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                          IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}"
                                          VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                          VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                          IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}"
                                          IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                          IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                          ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}"
                                          IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                          BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
                                          AutomationProperties.AccessibilityView="Raw">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <Border Height="{TemplateBinding RefreshHeaderHeight}"
                                            x:Name="PullToRefreshIndicator"
                                            Background="Transparent">
                                        <Grid HorizontalAlignment="Center">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="auto" />
                                                <ColumnDefinition Width="auto" />
                                            </Grid.ColumnDefinitions>
                                            <Grid Width="40">
                                                <Viewbox x:Name="Arrow"
                                                         Height="15"
                                                         VerticalAlignment="Top"
                                                         Margin="0,4,0,0"
                                                         RenderTransformOrigin="0.5,0.5">
                                                    <Viewbox.RenderTransform>
                                                        <CompositeTransform Rotation="180" />
                                                    </Viewbox.RenderTransform>
                                                    <Path Width="12"
                                                          Height="13"
                                                          Stretch="Fill"
                                                          Fill="{TemplateBinding ArrowColor}"
                                                          Data="M 20.4289,10.4376L 25,15.0087L 23.571,16.4376L 20.0291,12.8957L 20.0291,21.9999L 18.0083,21.9999L 18.0083,12.8583L 14.4289,16.4377L 13,15.0087L 17.5624,10.429L 19.0087,9" />
                                                </Viewbox>
                                            </Grid>
                                            <TextBlock Grid.Column="1"
                                                       Foreground="{TemplateBinding Foreground}"
                                                       FontSize="20"
                                                       x:Name="TextPull"
                                                       Text="{TemplateBinding PullText}" />
                                            <TextBlock Foreground="{TemplateBinding Foreground}"
                                                       FontSize="20"
                                                       x:Name="TextRefresh"
                                                       Visibility="Collapsed"
                                                       Text="{TemplateBinding RefreshText}"
                                                       Grid.Column="1" />
                                        </Grid>
                                    </Border>
                                    <ItemsPresenter Header="{TemplateBinding Header}"
                                                    HeaderTemplate="{TemplateBinding HeaderTemplate}"
                                                    HeaderTransitions="{TemplateBinding HeaderTransitions}"
                                                    Footer="{TemplateBinding Footer}"
                                                    FooterTemplate="{TemplateBinding FooterTemplate}"
                                                    FooterTransitions="{TemplateBinding FooterTransitions}"
                                                    Padding="{TemplateBinding Padding}"
                                                    Grid.Row="1" />
                                    <AppBarButton x:Name="RefreshButton"
                                                  Icon="Refresh"
                                                  Label="Refresh"
                                                  RequestedTheme="Light"
                                                  Margin="20"
                                                  HorizontalAlignment="Right"
                                                  VerticalAlignment="Top"
                                                  Visibility="Collapsed" 
                                                  Grid.Row="1"/>
                                </Grid>
                            </ScrollViewer>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

In me project VkMedia added reference to Controllers. And in Mainview.xaml code: xmlns:controls="using:Controllers.Controls" ....

<controls:PullToRefreshListView
                            ItemsSource="{Binding TrackListItems}"
                            RefreshCommand="{Binding RefreshCommand}">
                            <controls:PullToRefreshListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <TextBlock Text="{Binding FirstName}" />
                                    </Grid>
                                </DataTemplate>
                            </controls:PullToRefreshListView.ItemTemplate>
                        </controls:PullToRefreshListView>

arsenium avatar Jan 30 '16 13:01 arsenium

ops..xaml in class library - it is not right ? It looks like it's my fault

arsenium avatar Jan 30 '16 13:01 arsenium

Moved Controls and Themes folder in my project. But nothing has changed, the error remained. App working fine. Error only in Xaml Designer.

arsenium avatar Jan 30 '16 13:01 arsenium

you can prevent this error by disabling project code button which stands at the bottom of the xaml designer window. its probably happening due to that we created a subclass of listview. xaml designer may not be able to create a new instance of a custom element. so because of that while invoking refreshcontent event 'this' keyword returns null.

depyronick avatar May 05 '16 12:05 depyronick