简体   繁体   English

控制焦点面板

[英]Panel on Control Focus

I am working on a multi-lingual WPF app.我正在开发一个多语言 WPF 应用程序。 The user must provide input for multiple languages at same time.用户必须同时提供多种语言的输入。 This works but it also moves fields below it.这有效,但它也会移动其下方的字段。

What I am looking for is somewhat like this:我正在寻找的是有点像这样:

What I have done so far is below:到目前为止我所做的如下:

    <Label Grid.Column="0" Grid.Row="0"  Content="Field1" Padding="0" Style="{DynamicResource ControlLabel}"/>
<Label Grid.Column="1" Grid.Row="0" Content=":" Style="{DynamicResource ControlLabelMiddle}"/>
<StackPanel Grid.Column="2" Grid.Row="0" Margin="3"  Style="{Binding RelativeSource={RelativeSource TemplatedParent}}">
    <TextBox x:Name="txtField1" Height="23" GotKeyboardFocus="txtField1_GotKeyboardFocus" />
    <Grid Background="White" x:Name="pnlField1" Visibility="Collapsed" Panel.ZIndex="99">
        <Border BorderBrush="blue" BorderThickness="3">
        <StackPanel Background="White" Margin="5">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <Label Content="Language2" HorizontalAlignment="Left"/>
            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="10" Padding="2" >
                <Hyperlink Hyperlink.Click="btnClose_Click" x:Name="btnClose" >X</Hyperlink>
                </TextBlock>
            </StackPanel>
            <TextBox x:Name="txtField_Second" Height="23" Width="280" />
        </StackPanel>
        </Border>
    </Grid>
</StackPanel>

When the above control gets focus, my second language panel comes up.当上面的控件获得焦点时,我的第二语言面板就会出现。 But it moves my next row controls down and doesn't look good.但它把我的下一行控件向下移动,看起来不太好。

To keep the panels from moving, try placing them in a Grid , rather than a StackPanel .要防止面板移动,请尝试将它们放置在Grid ,而不是StackPanel This enables you to specifically define where each element is placed in the Grid .这使您能够明确定义每个元素在Grid放置位置。 In a StackPanel , elements "stack" on top of each other.StackPanel ,元素“堆叠”在彼此的顶部。 As contents of the panels change, the amount of space each element takes up in the "stack" also has the potential to change.随着面板内容的变化,每个元素在“堆栈”中占据的空间量也有可能发生变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM