2016-05-17 6 views
0

Ich habe ein Raster mit mehreren Zeilen und Zeilen Definitionen.Fokus geht auf übergeordnete Raster statt Textfeld

<Grid x:Name="RContentGrid" Grid.Column="0"> 
    <Grid.RowDefinitions> 
     <RowDefinition Name="RLabelRowDefinition" Height="40"></RowDefinition> 
     <RowDefinition Name="HeadingsRowDefinition" Height="40"></RowDefinition> 
     <RowDefinition Name="1RowDefinition" Height="Auto"></RowDefinition> 
     <RowDefinition Name="2RowDefinition" Height="Auto"></RowDefinition> 
     <RowDefinition Name="LineRowDefinition" Height="Auto"></RowDefinition> 
     <RowDefinition Name="3RowDefinition" Height="Auto"></RowDefinition> 
     <RowDefinition Name="4RowDefinition" Height="Auto"></RowDefinition> 
     <RowDefinition Name="5RowDefinition" Height="Auto"></RowDefinition> 
     <RowDefinition Name="ErrorRowDefinition" Height="Auto"></RowDefinition> 
    </Grid.RowDefinitions> 
... 

Einer der Textfelder wie folgt aussieht:

<TextBox x:Name="TextBoxRight1" 
    Grid.Row="2" Grid.Column="1" Margin="5" 
    Style="{DynamicResource g_TextInputWithLabelSmall}" 
    FontFamily="Arial Narrow" FontSize="16" /> 

Die genannte Art sieht wie folgt aus:

<Style x:Key="g_TextInputWithLabelSmall" TargetType="{x:Type TextBox}"> 
    <Setter Property="Helpers:ClientKeyboardController.AutoShowKeyboard" Value="True"/> 
    <Setter Property="Helpers:ClientKeyboardController.AutoHideKeyboard" Value="True"/> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> 
    <Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/> 
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Setter Property="HorizontalContentAlignment" Value="Left"/> 
    <Setter Property="Padding" Value="2"/> 
    <Setter Property="AllowDrop" Value="true"/> 
    <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> 
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TextBox}"> 
       <Grid MinHeight="35" MinWidth="55"> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="SelectedStates"> 
          <VisualState x:Name="CustomSelected"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="Black"/> 
            </ColorAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_ContentHost"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Offset)" Storyboard.TargetName="Bd"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/> 
            </DoubleAnimationUsingKeyFrames> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="Black"/> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="CustomUnSelected"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_ContentHost"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/> 
            </DoubleAnimationUsingKeyFrames> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="#FF666666"/> 
            </ColorAnimationUsingKeyFrames> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="#FFCCCCCC"/> 
            </ColorAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Offset)" Storyboard.TargetName="Bd"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" Storyboard.TargetName="Bd"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(Brush.RelativeTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="Bd"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="-45"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="0.6"/> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="CommonStates"> 
          <VisualState x:Name="Normal"/> 
          <VisualState x:Name="Disabled"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="#33000000"/> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="ReadOnly"> 
           <Storyboard> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="#33000000"/> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="MouseOver"/> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="FocusStates"> 
          <VisualState x:Name="Unfocused"/> 
          <VisualState x:Name="Focused"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_ContentHost"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Offset)" Storyboard.TargetName="Bd"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" Storyboard.TargetName="Bd"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
            </DoubleAnimationUsingKeyFrames> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="Black"/> 
            </ColorAnimationUsingKeyFrames> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Bd"> 
             <EasingColorKeyFrame KeyTime="0" Value="Black"/> 
            </ColorAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="ValidationStates"> 
          <VisualState x:Name="Valid"/> 
          <VisualState x:Name="InvalidFocused"> 
           <Storyboard> 
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="border"> 
             <EasingThicknessKeyFrame KeyTime="0" Value="2"/> 
            </ThicknessAnimationUsingKeyFrames> 
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="Bd"> 
             <EasingThicknessKeyFrame KeyTime="0" Value="0"/> 
            </ThicknessAnimationUsingKeyFrames> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="PART_ContentHost"> 
             <EasingColorKeyFrame KeyTime="0" Value="#FFE3001B"/> 
            </ColorAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_ContentHost"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="InvalidUnfocused"> 
           <Storyboard> 
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="border"> 
             <EasingThicknessKeyFrame KeyTime="0" Value="2"/> 
            </ThicknessAnimationUsingKeyFrames> 
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="Bd"> 
             <EasingThicknessKeyFrame KeyTime="0" Value="0"/> 
            </ThicknessAnimationUsingKeyFrames> 
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="PART_ContentHost"> 
             <EasingColorKeyFrame KeyTime="0" Value="#FFE3001B"/> 
            </ColorAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_ContentHost"> 
             <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <Grid VerticalAlignment="Bottom" Margin="0,-75,0,50" Height="Auto"> 
         <TextBlock x:Name="textBlock" TextWrapping="Wrap" IsHyphenationEnabled="True" Height="Auto" Style="{DynamicResource g_TextFieldLabel_14_100}" VerticalAlignment="Bottom" Margin="0,0,2,0" Width="Auto" Opacity="0.6"><Run Text="{TemplateBinding Tag}"/><Run Text=" "/><Run Foreground="#88000000" Text="{TemplateBinding ToolTip}"/></TextBlock> 
        </Grid> 
        <Border x:Name="border" BorderBrush="{DynamicResource ErrorColor}"> 
         <Border x:Name="Bd" SnapsToDevicePixels="true" Background="White" BorderThickness="1"> 
          <Border.BorderBrush> 
           <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
            <LinearGradientBrush.RelativeTransform> 
             <TransformGroup> 
              <ScaleTransform CenterY="0.5" CenterX="0.5"/> 
              <SkewTransform CenterY="0.5" CenterX="0.5"/> 
              <RotateTransform CenterY="0.5" CenterX="0.5" Angle="135"/> 
              <TranslateTransform/> 
             </TransformGroup> 
            </LinearGradientBrush.RelativeTransform> 
            <GradientStop Color="#FFCCCCCC" Offset="0.5"/> 
            <GradientStop Color="#FF666666" Offset="0.5"/> 
           </LinearGradientBrush> 
          </Border.BorderBrush> 
          <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Template="{DynamicResource g_TextInput}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" Opacity="0.5"/> 
         </Border> 
        </Border> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

Das Problem, das ich Gesicht ist, dass, wenn der Benutzer klickt auf die Textbox auf dem untere Hälfte der Fokus geht auf das obige Raster. Nur wenn der Benutzer auf die obere Hälfte klickt, kommt der Fokus auf die Textbox.

Ich habe versucht, die folgenden: - Versucht, die Zeilendefinition der Zeilen ändert - Versucht, die Höhe des

Zeile zu ändern Was ich hier fehlt?

+2

Es ist wie x aussieht: Name = "textblock" in der Stilvorlage (genauer gesagt, es ist das Eltern-Grid) erzeugt Überlappungen aufgrund der negativen "Marge", so dass es in Z-Reihenfolge gerendert wird, jede Box überlappt die darüber liegende mit ihrem Hittest-Sichtbarkeitsbereich. –

Antwort

0

Dank Chris W. :)

Durch die Marge auf dem Grid zu entfernen war ich in der Lage, das Problem zu lösen:

<Grid VerticalAlignment="Bottom" Height="Auto"> 
        <TextBlock x:Name="textBlock" TextWrapping="Wrap" IsHyphenationEnabled="True" Height="Auto" Style="{DynamicResource g_TextFieldLabel_14_100}" VerticalAlignment="Bottom" Margin="0,0,2,0" Width="Auto" Opacity="0.6"><Run Text="{TemplateBinding Tag}"/><Run Text=" "/><Run Foreground="#88000000" Text="{TemplateBinding ToolTip}"/></TextBlock> 
       </Grid> 
Verwandte Themen