C# 对实例方法的委托不能为null';这';在Windows Phone 8.1自定义控件中
在针对windows phone 8.1的非silverlight项目中,我遇到了问题。我创建了自定义控件PullToRefreshPanel,添加GridView后,Xaml设计器显示错误:C# 对实例方法的委托不能为null';这';在Windows Phone 8.1自定义控件中,c#,xaml,windows-phone-8.1,windows-rt,C#,Xaml,Windows Phone 8.1,Windows Rt,在针对windows phone 8.1的非silverlight项目中,我遇到了问题。我创建了自定义控件PullToRefreshPanel,添加GridView后,Xaml设计器显示错误: Delegate to an instance method cannot have null 'this' 如何捕捉这个错误?我怎么知道是因为我的错误 控件的类型和样式: <Style TargetType="controls:PullToRefreshPanel"> <
Delegate to an instance method cannot have null 'this'
如何捕捉这个错误?我怎么知道是因为我的错误
控件的类型和样式:
<Style TargetType="controls:PullToRefreshPanel">
<Setter Property="FontSize" Value="24" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:PullToRefreshPanel">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Pull">
<Storyboard>
<FadeInThemeAnimation TargetName="PullContent" />
<FadeOutThemeAnimation TargetName="RefreshContent" />
</Storyboard>
</VisualState>
<VisualState x:Name="Refresh">
<Storyboard>
<FadeInThemeAnimation TargetName="RefreshContent" />
<FadeOutThemeAnimation TargetName="PullContent" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer x:Name="ScrollViewer"
HorizontalScrollMode="Disabled"
VerticalScrollBarVisibility="Hidden"
ZoomMode="Disabled">
<StackPanel x:Name="StackPanel">
<Grid Name="PullGrid" Height="{TemplateBinding InvisiblePullRange}">
<Grid Height="{TemplateBinding PullRange}" VerticalAlignment="Bottom">
<ContentControl x:Name="RefreshContent"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding RefreshContent}" />
<ContentControl x:Name="PullContent"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding PullContent}" />
</Grid>
</Grid>
<Grid x:Name="ContentGrid">
<ContentPresenter />
</Grid>
</StackPanel>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我使用Visual Studio 2015和Windows Phone 8.1 XAML项目。
有什么想法吗
更新:
也许是一个bug Xaml设计器?该应用程序运行良好。仅在Xaml设计器中出错。 我从控制代码中删除了所有引用EventHandler PullToRefresh,错误仍然存在。 这就是不断出现的错误:
您必须实例化PullToRefresh eventhandler。它正在获取空引用异常。检查此答案如何正确执行?该方法是通过Xaml分配的。还是我不明白的?在我所看到的创建EventHandler的所有示例中,都使用了与我相同的代码。我认为这个错误是由Xaml引起的?也许是Xaml设计器的错误?该应用程序运行良好。仅在Xaml设计器中出错。
<Style TargetType="controls:PullToRefreshPanel">
<Setter Property="FontSize" Value="24" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:PullToRefreshPanel">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Pull">
<Storyboard>
<FadeInThemeAnimation TargetName="PullContent" />
<FadeOutThemeAnimation TargetName="RefreshContent" />
</Storyboard>
</VisualState>
<VisualState x:Name="Refresh">
<Storyboard>
<FadeInThemeAnimation TargetName="RefreshContent" />
<FadeOutThemeAnimation TargetName="PullContent" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer x:Name="ScrollViewer"
HorizontalScrollMode="Disabled"
VerticalScrollBarVisibility="Hidden"
ZoomMode="Disabled">
<StackPanel x:Name="StackPanel">
<Grid Name="PullGrid" Height="{TemplateBinding InvisiblePullRange}">
<Grid Height="{TemplateBinding PullRange}" VerticalAlignment="Bottom">
<ContentControl x:Name="RefreshContent"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding RefreshContent}" />
<ContentControl x:Name="PullContent"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding PullContent}" />
</Grid>
</Grid>
<Grid x:Name="ContentGrid">
<ContentPresenter />
</Grid>
</StackPanel>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>