2017-09-06 6 views
0

UWP:ToggleButtonのMouse OverとMouse Pressedの背景を削除するにはどうすればよいですか?UWP ToggleButtonのマウスオーバーとマウスが押された背景を削除する

XAML:

(PS:!これはButton上で動作します)

<Style TargetType="ToggleButton"> 
     <Setter Property="Foreground" Value="White"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ToggleButton"> 
        <Grid x:Name="RootGrid" Background="{TemplateBinding Background}"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal"> 
           </VisualState> 
           <VisualState x:Name="PointerOver"> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <ContentPresenter 
          x:Name="ContentPresenter" 
          BorderBrush="Transparent" 
          BorderThickness="{TemplateBinding BorderThickness}" 
          Content="{TemplateBinding Content}" 
          ContentTransitions="{TemplateBinding ContentTransitions}" 
          ContentTemplate="{TemplateBinding ContentTemplate}" 
          Padding="{TemplateBinding Padding}" 
          HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
          VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
          AutomationProperties.AccessibilityView="Raw" 
          Foreground="White"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

結果(黒い四角の周囲とその中のやや暗い背景に注意してください):

enter image description here

同じボタンのもう1つの画像がチェックされていれば、恐ろしい見た目になるかもしれません。

enter image description here

+0

は、私は強く、ハードにコーディングされたのではなく、その外観を制御するために、 'ToggleButton'のスタイリングを使って試してみることをお勧めしますこのような画像。 –

答えて

0

https://msdn.microsoft.com/en-us/library/windows/apps/mt299157.aspx

例は以下の罰金に動作します:

 <Style x:Key="NakedToggleButton" TargetType="ToggleButton"> 
      <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" /> 
      <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/> 
      <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundTransparentBrush}" /> 
      <Setter Property="BorderThickness" Value="{ThemeResource ToggleButtonBorderThemeThickness}" /> 
      <Setter Property="Padding" Value="8,4,8,4" /> 
      <Setter Property="HorizontalAlignment" Value="Left" /> 
      <Setter Property="VerticalAlignment" Value="Center" /> 
      <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> 
      <Setter Property="FontWeight" Value="Normal" /> 
      <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> 
      <Setter Property="UseSystemFocusVisuals" Value="True" /> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="ToggleButton"> 
         <Grid x:Name="RootGrid" Background="Transparent"> 
          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup x:Name="CommonStates"> 
            <VisualState x:Name="PointerOver"> 
            </VisualState> 
            <VisualState x:Name="Pressed"> 
            </VisualState> 
            <VisualState x:Name="Disabled"> 
            </VisualState> 
            <VisualState x:Name="Checked"> 
            </VisualState> 
            <VisualState x:Name="CheckedPointerOver"> 
            </VisualState> 
            <VisualState x:Name="CheckedPressed"> 
            </VisualState> 
            <VisualState x:Name="CheckedDisabled"> 
            </VisualState> 
            <VisualState x:Name="Indeterminate"> 
            </VisualState> 
            <VisualState x:Name="IndeterminatePointerOver"> 
            </VisualState> 
            <VisualState x:Name="IndeterminatePressed"> 
            </VisualState> 
            <VisualState x:Name="IndeterminateDisabled"> 
            </VisualState> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
          <ContentPresenter x:Name="ContentPresenter" 
               BorderBrush="{TemplateBinding BorderBrush}" 
               BorderThickness="{TemplateBinding BorderThickness}" 
               Content="{TemplateBinding Content}" 
               ContentTransitions="{TemplateBinding ContentTransitions}" 
               ContentTemplate="{TemplateBinding ContentTemplate}" 
               Padding="{TemplateBinding Padding}" 
               HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
               VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
               AutomationProperties.AccessibilityView="Raw"/> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
関連する問題