2016-08-12 1 views
1

J'ai le code suivant:Comportement étrange de ScrollViewer dans tabcontrol

<Window x:Class="WpfApplication5.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:WpfApplication5" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <TabControl> 
     <TabControl.Items> 
      <TabItem> 
       <TabItem.Header>tabItem1</TabItem.Header> 
       <TabItem.Content> 
        <ScrollViewer HorizontalScrollBarVisibility="Disabled"> 
         <WrapPanel> 
          <Image Source="RentgenogramOfWrist.jpg" Width="500"></Image> 
          <Button Width="300" Height="300"/> 
         </WrapPanel> 
        </ScrollViewer> 
       </TabItem.Content> 
      </TabItem> 
      <TabItem> 
       <TabItem.Header>tabItem2</TabItem.Header> 
       <TabItem.Content> 
        <ScrollViewer HorizontalScrollBarVisibility="Disabled"> 
         <WrapPanel> 
          <Image Source="RentgenogramOfWrist.jpg" Width="500"></Image> 
          <Button Width="300" Height="300"/> 
         </WrapPanel> 
        </ScrollViewer> 
       </TabItem.Content> 
      </TabItem> 
     </TabControl.Items> 
    </TabControl> 
</Grid> 

Le problème est que lorsque le programme est en cours d'exécution et je passe à la seconde TabItem ScrollViewer défilera au début de la touche. Quand je passe maintenant de la deuxième tabItem à la première, la même chose se produit.

Répondre

1

La propriété Focusable de Button est true by default, de sorte que le ScrollViewer fait défiler le bouton.

Set

<Button Width="300" Height="300" Focusable="False"/> 

pour un d'eux et voir quels changements.