" TemplateBinding'在' {'之后使用必须是标记扩展" UWP GridView

时间:2016-11-03 09:28:24

标签: xaml uwp win-universal-app windows-10-universal uwp-xaml

我的MainPage.xaml上有一个GridView。我想在GeneratedItemContainerStyle中更改最外边框画笔颜色:

Screenshot

所以,我点击"编辑副本"创建了一个新的自定义样式。来自GridView / Additional Templates / GeneratedItemContainerStyle。

然后,这个XAML样式出现在我的App.xaml中。

<Style x:Key="GridViewItemStyle1" TargetType="GridViewItem">
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
    <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
    <Setter Property="Background" Value="{ThemeResource GridViewItemBackground}"/>
    <Setter Property="Foreground" Value="{ThemeResource GridViewItemForeground}"/>
    <Setter Property="TabNavigation" Value="Local"/>
    <Setter Property="IsHoldingEnabled" Value="True"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Margin" Value="0,0,4,4"/>
    <Setter Property="MinWidth" Value="{ThemeResource GridViewItemMinWidth}"/>
    <Setter Property="MinHeight" Value="{ThemeResource GridViewItemMinHeight}"/>
    <Setter Property="AllowDrop" Value="False"/>
    <Setter Property="UseSystemFocusVisuals" Value="True"/>
    <Setter Property="FocusVisualMargin" Value="-2"/>
    <Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource GridViewItemFocusVisualPrimaryBrush}"/>
    <Setter Property="FocusVisualPrimaryThickness" Value="2"/>
    <Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource GridViewItemFocusVisualSecondaryBrush}"/>
    <Setter Property="FocusVisualSecondaryThickness" Value="1"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="GridViewItem">
                <ListViewItemPresenter CheckBrush="{ThemeResource GridViewItemCheckBrush}" ContentMargin="{TemplateBinding Padding}" CheckMode="{ThemeResource GridViewItemCheckMode}" ContentTransitions="{TemplateBinding ContentTransitions}" CheckBoxBrush="{ThemeResource GridViewItemCheckBoxBrush}" DragForeground="{ThemeResource GridViewItemDragForeground}" DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" DragBackground="{ThemeResource GridViewItemDragBackground}" DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" FocusVisualPrimaryBrush="{TemplateBinding FocusVisualPrimaryBrush}" FocusVisualSecondaryThickness="{TemplateBinding FocusVisualSecondaryThickness}" FocusBorderBrush="{ThemeResource GridViewItemFocusBorderBrush}" FocusVisualMargin="{TemplateBinding FocusVisualMargin}" FocusVisualPrimaryThickness="{TemplateBinding FocusVisualPrimaryThickness}" FocusSecondaryBorderBrush="{ThemeResource GridViewItemFocusSecondaryBorderBrush}" FocusVisualSecondaryBrush="{TemplateBinding FocusVisualSecondaryBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Control.IsTemplateFocusTarget="True" PointerOverForeground="{ThemeResource GridViewItemForegroundPointerOver}" PressedBackground="{ThemeResource GridViewItemBackgroundPressed}" PlaceholderBackground="{ThemeResource GridViewItemPlaceholderBackground}" PointerOverBackground="{ThemeResource GridViewItemBackgroundPointerOver}" ReorderHintOffset="{ThemeResource GridViewItemReorderHintThemeOffset}" SelectedPressedBackground="{ThemeResource GridViewItemBackgroundSelectedPressed}" SelectionCheckMarkVisualEnabled="{ThemeResource GridViewItemSelectionCheckMarkVisualEnabled}" SelectedForeground="{ThemeResource GridViewItemForegroundSelected}" SelectedPointerOverBackground="{ThemeResource GridViewItemBackgroundSelectedPointerOver}" SelectedBackground="{ThemeResource GridViewItemBackgroundSelected}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

之后,我尝试部署我的应用程序,出现了这个错误:

  

键入&#39; TemplateBinding&#39;在&#39; {&#39;之后使用必须是标记扩展。 XAML代码的ListViewItemPresenter部分中的错误代码0x09c4。**。

我该如何解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:5)

FocusVisual*属性仅存在于周年纪念更新中。您可以将项目属性中的最小SDK版本设置为“Windows 10 Anniversary Edition”(通常为14393版)。

您是在谈论每个GridViewItem的2px边框吗?这不是焦点边界;你必须覆盖这些资源:

<GridView>
    <GridView.Resources>
        <!--
            These will apply to this GridView only. Put in higher scope
            (page or app) depending on what you want it to affect.
        -->
        <SolidColorBrush x:Key="GridViewItemBackgroundSelected" Color="Red"/>
        <SolidColorBrush x:Key="GridViewItemBackgroundSelectedPointerOver" Color="Blue"/>
        <SolidColorBrush x:Key="GridViewItemBackgroundSelectedPressed" Color="LimeGreen"/>
        <SolidColorBrush x:Key="GridViewItemBackgroundPointerOver" Color="Magenta"/>
        <SolidColorBrush x:Key="GridViewItemBackgroundPressed" Color="Violet"/>
    </GridView.Resources>
</GridView>