2012-09-16 13 views
9

ho la più semplice applicazione mai: singola finestra con un unico pulsante di commutazione:ToggleButton non mostra alcuna condizione

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <ToggleButton Content="This is my ToggleButton" /> 
    </Grid> 
</Window> 

Quando ora clicco sul pulsante di commutazione, in realtà non accade nulla. Quando imposto il gestore di eventi per l'evento Checked e Unchecked, quindi faccio clic sul pulsante, prima viene generato Checked e poi Unchecked. Quindi il pulsante sembra funzionare correttamente ...

Sto compilando su .NET 4.5 e sto usando Windows 8 RTM.

Questo comportamento è correlato allo stile di visualizzazione dei pulsanti di Windows 8 (nessun bordo "3D")? Qualcuno può confermare?

UPDATE 1 ho fatto un'immagine per mostrare quello che volevo dire:

Windows 8 vs Windows 7 toggle button

Come si vede, in Windows 8 "non succede nulla" quando si fa clic sul pulsante di selezione, semplicemente non viene "attivato". Questo sembra essere un bug, relative a Windows 8 stile di pulsanti che mostrano ...

UPDATE: 30 mag 2013: Un hotfix è avalible: http://support.microsoft.com/kb/2805222
See Issue # 5 sotto WPF
Purtroppo non risolve il problema per me :(

+1

Che cosa esattamente cosa si intende per "non succede niente"? Il pulsante non appare premuto quando si fa clic su di esso? Se questo è il caso, allora potrebbe essere qualcosa relativo a Windows 8 come hai detto tu. –

+0

sì ... cosa intendi perché non succede nulla? Il pulsante non va giù? – Seva

+0

forse dovresti definire una dimensione per il pulsante di commutazione – Seva

risposta

5

Questo è un difetto confermato in WPF. La soluzione consiste nello stile del controllo di conseguenza, sebbene una correzione possa essere considerata dal gruppo di prodotti. contattare il supporto Microsoft

+0

[già fatto che qualche tempo fa] (https://connect.microsoft.com/VisualStudio/feedback/details/763597/togglebutton-doesnt-show-any-state) poiché nessuno voleva rispondere alla mia domanda – GameScripting

4

Per tutti coloro che vogliono un po 'di codice per cominciare, si può prendere il codice che ho usato per lo stile miei controlli:

<Application.Resources> 

     <!-- Toogle button fix (includes custom button + toggle button style) --> 
     <Style TargetType="{x:Type Button}"> 
      <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/> 
      <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/> 
      <Setter Property="BorderThickness" Value="1"/> 
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
      <Setter Property="HorizontalContentAlignment" Value="Center"/> 
      <Setter Property="VerticalContentAlignment" Value="Center"/> 
      <Setter Property="Padding" Value="1"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type Button}"> 
         <Border BorderThickness="1" BorderBrush="#FFA4A4A4"> 
          <Grid> 
           <Rectangle x:Name="Rectangle_Background" Fill="#FFEDEDED" /> 
           <ContentPresenter x:Name="ContentPresenter_Content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
          </Grid> 
         </Border> 
         <ControlTemplate.Triggers> 
          <Trigger Property="IsEnabled" Value="false"> 
           <Setter TargetName="Rectangle_Background" Property="Fill" Value="#f7f7f7"/> 
           <Setter TargetName="ContentPresenter_Content" Property="Opacity" Value="0.5"/> 
          </Trigger> 
          <Trigger Property="IsMouseOver" Value="True"> 
           <Setter TargetName="Rectangle_Background" Property="Fill" Value="#e0e0e0" /> 
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

     <Style TargetType="{x:Type ToggleButton}"> 
      <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/> 
      <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/> 
      <Setter Property="BorderThickness" Value="1"/> 
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
      <Setter Property="HorizontalContentAlignment" Value="Center"/> 
      <Setter Property="VerticalContentAlignment" Value="Center"/> 
      <Setter Property="Padding" Value="1"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ToggleButton}"> 
         <Border BorderThickness="1" BorderBrush="#FFA4A4A4"> 
          <Grid> 
           <Rectangle x:Name="Rectangle_Background" Fill="#FFEDEDED" /> 
           <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
          </Grid> 
         </Border> 
         <ControlTemplate.Triggers> 
          <Trigger Property="IsEnabled" Value="false"> 
           <Setter TargetName="Rectangle_Background" Property="Fill" Value="#ADADAD"/> 
          </Trigger> 
          <Trigger Property="IsMouseOver" Value="True"> 
           <Setter TargetName="Rectangle_Background" Property="Fill" Value="#e0e0e0" /> 
          </Trigger> 
          <Trigger Property="IsChecked" Value="true"> 
           <Setter Property="Fill" TargetName="Rectangle_Background" Value="#bee6fd"/> 
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

    </Application.Resources> 
Problemi correlati