问题描述
在 TextBox
上添加 Expander
后,我无法点击原始的 TextBox
.例如
After adding an Expander
over a TextBox
, I'm not able to click on the original TextBox
.For example
<Grid Background="Yellow" Focusable="False">
<TextBox Margin="0,20,0,0" Background="Azure" Width="150" Height="30"/>
<Expander Focusable="False">
<Grid Background="White" >
<TextBox Background="LightGreen" Width="150" Height="30"/>
</Grid>
</Expander>
</Grid>
上面的 azure TextBox 不可点击:我必须在其中使用 Tab...
the above azure TextBox is not clickable: I have to tab in it...
...虽然绿色的效果很好
... while the green one works fine
编辑我试图在扩展器中添加 false focusable
EditI've tried to add false focusable in the expander
推荐答案
你的 Expander 是放在你的 azure TextBox 上面(它们都放在同一个单元格 0,0 的同一个网格上),所以 azure TextBox 不能被点击.如果您通过在 Expander 之后放置 azure TextBox 来更改它们的 z-order,则 azure TextBox 将变为可点击(但它会阻止绿色 TextBox 可点击):
Your Expander is placed on top of your azure TextBox (they both are placed on the same grid in the same cell 0,0), so azure TextBox can not be clicked. If you change their z-order by placing azure TextBox after Expander, then azure TextBox will become clickable (but it will prevent green TextBox to be clickable):
<Grid Background="Yellow" Focusable="False">
<Expander Focusable="False">
<Grid Background="White" >
<TextBox Background="LightGreen" Width="150" Height="30"/>
</Grid>
</Expander>
<TextBox Margin="0,20,0,0" Background="Azure" Width="150" Height="30"/>
</Grid>
如果将 2 个 TextBox 放置在另一个顶部,则不能有 2 个可点击.
You cannot have 2 TextBoxes to be clickable, if they are placed on top of one another.
为了实现您的目标(在 Expander 展开时访问一个 TextBox,在 Expander 折叠时访问另一个),您可以在扩展器展开时折叠 azure TextBox.这是一个如何使用触发器执行此操作的示例(或者为了简单起见,您可以在代码中执行此操作):
To achieve your goal (to access one TextBox when the Expander is expanded and the other one when the Expander is collapsed) you can collapse azure TextBox, when expander is expanded. Here is an example how to do it with Triggers (or you can do it in code for simplicity):
<Grid Background="Yellow">
<Expander Name="Expander">
<Grid Background="White" >
<TextBox Background="LightGreen" Width="150" Height="30"/>
</Grid>
</Expander>
<TextBox Name="AzureBox" Margin="0,20,0,0" Background="Azure" Width="150" Height="30">
<TextBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Expander, Path=IsExpanded}" Value="True">
<Setter Property="TextBox.Visibility" Value="Collapsed"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
这篇关于无法在带有扩展器的 TextBox 中单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!