我在Windows标签8.1上运行的Windows 8.1应用程序也是, 我之前在Windows 8.1操作系统和Visual Studio 2013上创建了这个版本,之后当我转到Windows 10操作系统和Visual Studio 2015 Update 3时,有一个例外并经过调查。 ListViewItemPresenter的一些属性在运行时导致异常。 这三个属性是
ListviewItem样式位于单独的文件Resource Dictionary中, 但是当我尝试将所有样式放在同一个文件(AppBarMenu.xaml)中时,样式正在运行并且没有抛出错误。
注意:我在此应用程序中使用了MVVMCROSS框架,当我滑动或点击应用程序时会发生错误。
以下是资源字典中的XAML样式。
<Style x:Key="ListViewItemStyle_Menu" TargetType="ListViewItem">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="IsHoldingEnabled" Value="True"/>
<Setter Property="Margin" Value="0,0,18,2"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
ContentTransitions="{TemplateBinding ContentTransitions}"
Padding="{TemplateBinding Padding}"
SelectionCheckMarkVisualEnabled="True"
CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}"
CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}"
CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}"
SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}"
SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}"
SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}"
SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}"
SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
PointerOverBackgroundMargin="1"
ContentMargin="2" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在我的Listview中这里是XAML(AppBarMenu.xaml)
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="100" Margin="0,10,0,0">
<Border.Background>
<ImageBrush Stretch="None" ImageSource="{Binding IconUri}"/>
</Border.Background>
</Border>
<Rectangle HorizontalAlignment="Center" Height="10" VerticalAlignment="Bottom" Width="10" RenderTransformOrigin="0.5,0.5" Margin="0,0,0,-5">
<Rectangle.Fill>
<SolidColorBrush Color="{StaticResource BaseColor01}"/>
</Rectangle.Fill>
<Rectangle.RenderTransform>
<CompositeTransform Rotation="45"/>
</Rectangle.RenderTransform>
</Rectangle>
<Border Grid.Row="1" Height="60" BorderThickness="1,0,1,1">
<Border.Background>
<SolidColorBrush Color="{StaticResource BaseColor01}"/>
</Border.Background>
</Border>
<TextBlock Text="{Binding Name}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}"
Style="{StaticResource BaseTextBlockStyle}"
Margin="15,0"
FontWeight="SemiLight"
FontSize="24"
VerticalAlignment="Center"
Grid.Row="1"
TextAlignment="Center"/>
<StackPanel Orientation="Vertical" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,7,7,0">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">
<Ellipse HorizontalAlignment="Left" Height="6" VerticalAlignment="Top" Width="6">
<Ellipse.Fill>
<SolidColorBrush Color="{StaticResource BaseColor02}"/>
</Ellipse.Fill>
</Ellipse>
<Ellipse HorizontalAlignment="Left" Height="6" VerticalAlignment="Top" Width="6" Margin="3,0">
<Ellipse.Fill>
<SolidColorBrush Color="{StaticResource BaseColor02}"/>
</Ellipse.Fill>
</Ellipse>
<Ellipse HorizontalAlignment="Left" Height="6" VerticalAlignment="Top" Width="6">
<Ellipse.Fill>
<SolidColorBrush Color="{StaticResource BaseColor02}"/>
</Ellipse.Fill>
</Ellipse>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,3">
<Ellipse HorizontalAlignment="Left" Height="6" VerticalAlignment="Top" Width="6" Margin="3,0">
<Ellipse.Fill>
<SolidColorBrush Color="{StaticResource BaseColor02}"/>
</Ellipse.Fill>
</Ellipse>
<Ellipse HorizontalAlignment="Left" Height="6" VerticalAlignment="Top" Width="6">
<Ellipse.Fill>
<SolidColorBrush Color="{StaticResource BaseColor02}"/>
</Ellipse.Fill>
</Ellipse>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">
<Ellipse HorizontalAlignment="Left" Height="6" VerticalAlignment="Top" Width="6">
<Ellipse.Fill>
<SolidColorBrush Color="{StaticResource BaseColor02}"/>
</Ellipse.Fill>
</Ellipse>
</StackPanel>
</StackPanel>
<Border Background="#01000000" Grid.RowSpan="2">
<i:Interaction.Behaviors>
<b:EventTriggerBehavior EventName="Tapped">
<ctrls:MediaElementPlayAction />
<b:InvokeCommandAction Command="{Binding Path=Selected}" />
</b:EventTriggerBehavior>
</i:Interaction.Behaviors>
</Border>
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
如果有人遇到同样的问题,请分享您的想法是什么原因导致此错误。
注意:我不是在寻找答案或解决方案,我只是在寻找原因。
谢谢大家。