【问题标题】:Windows Phone 8.1 AppBarButton Template not editableWindows Phone 8.1 AppBarButton 模板不可编辑
【发布时间】:2015-07-09 21:29:37
【问题描述】:

我无法在 Windows Phone 8.1 项目的 BottomAppBar 内重新定义 AppBarButton 的模板。

在 Visual Studio XAML 设计器中它会发生变化(它显示“按钮 2”文本),但是当我将它部署到手机或模拟器时,会应用默认模板。

我尝试右键单击控件,“编辑模板”,“编辑副本...”,但它不可用。是否可以重新定义此模板?

我的 XAML 代码(只是一个非常简化的示例):

<Page.BottomAppBar>
    <CommandBar>
        <CommandBar.SecondaryCommands>
            <AppBarButton
                Label="button">
                <AppBarButton.Template>
                    <ControlTemplate>
                        <TextBlock
                            Text="button 2" />
                    </ControlTemplate>
                </AppBarButton.Template>
            </AppBarButton>
        </CommandBar.SecondaryCommands>
    </CommandBar>
</Page.BottomAppBar>

我有安装了 Visual Studio Community 2013 Update 4 的 Windows 8.1 Pro。

【问题讨论】:

    标签: xaml visual-studio-2013 windows-phone-8.1 blend


    【解决方案1】:

    不,无法在 Windows Phone 8.1 上自定义前景色和背景色之外的应用栏。在 Windows Phone 上,应用栏是系统 UI,而不是作为 UI 的应用。

    如果您想自定义应用栏按钮,可以将它们放在停靠在页面底部的自定义面板中,而不是放在 Page.BottomAppBar 中

    【讨论】:

      【解决方案2】:

      您绝对可以右键单击并编辑副本。我最近才这样做。尝试在页面顶部放置一个临时 AppBarButton 并右键单击该按钮。以下是您需要时的默认样式:

                  <Style x:Key="AppBarButtonStyle1" TargetType="AppBarButton">
                  <Setter Property="Foreground" Value="{ThemeResource AppBarItemForegroundThemeBrush}"/>
                  <Setter Property="VerticalAlignment" Value="Top"/>
                  <Setter Property="HorizontalAlignment" Value="Left"/>
                  <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
                  <Setter Property="FontWeight" Value="Normal"/>
                  <Setter Property="Template">
                      <Setter.Value>
                          <ControlTemplate TargetType="AppBarButton">
                              <StackPanel x:Name="LayoutRoot" Background="Transparent" Width="80">
                                  <VisualStateManager.VisualStateGroups>
                                      <VisualStateGroup x:Name="ApplicationViewStates">
                                          <VisualState x:Name="FullSize"/>
                                          <VisualState x:Name="Compact">
                                              <Storyboard>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="TextLabel">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="LayoutRoot">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="48"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                              </Storyboard>
                                          </VisualState>
                                      </VisualStateGroup>
                                      <VisualStateGroup x:Name="CommonStates">
                                          <VisualState x:Name="Normal"/>
                                          <VisualState x:Name="Pressed">
                                              <Storyboard>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="Ellipse">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarItemForegroundThemeBrush}"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="Ellipse">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarItemForegroundThemeBrush}"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Content">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarItemPressedForegroundThemeBrush}"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                              </Storyboard>
                                          </VisualState>
                                          <VisualState x:Name="Disabled">
                                              <Storyboard>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="Ellipse">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarItemDisabledForegroundThemeBrush}"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Content">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarItemDisabledForegroundThemeBrush}"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="TextLabel">
                                                      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarItemDisabledForegroundThemeBrush}"/>
                                                  </ObjectAnimationUsingKeyFrames>
                                              </Storyboard>
                                          </VisualState>
                                      </VisualStateGroup>
                                  </VisualStateManager.VisualStateGroups>
                                  <Grid HorizontalAlignment="Center" Height="38.5" Margin="0,12,0,4" Width="38.5">
                                      <Ellipse x:Name="Ellipse" Fill="{ThemeResource AppBarItemBackgroundThemeBrush}" Height="38.5" Stroke="{ThemeResource AppBarItemForegroundThemeBrush}" StrokeThickness="2.5" UseLayoutRounding="False" Width="38.5"/>
                                      <Grid x:Name="ContentRoot" Background="Transparent">
                                          <ContentPresenter x:Name="Content" AutomationProperties.AccessibilityView="Raw" Content="{TemplateBinding Icon}" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                                      </Grid>
                                  </Grid>
                                  <TextBlock x:Name="TextLabel" Foreground="{ThemeResource AppBarItemForegroundThemeBrush}" FontSize="9.5" FontFamily="{TemplateBinding FontFamily}" Margin="0,0,0,10.5" TextAlignment="Center" TextWrapping="Wrap" Text="{TemplateBinding Label}" Width="70.5"/>
                              </StackPanel>
                          </ControlTemplate>
                      </Setter.Value>
                  </Setter>
              </Style>
      

      【讨论】:

      • 这适用于页面本身的 AppBarButton,但不适用于页面的 CommandBar
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多