将控件置于前方。

huangapple go评论64阅读模式
英文:

How to bring a control to the front

问题

我有一个ListView,它作为Entry的建议框。

界面以网格方式组织,当没有建议时,ListView被隐藏,出于实际原因,我想将ListView的声明放在Entry旁边。但这意味着它被添加到网格之前,与建议框相同位置后面声明的控件,因此它会被放在该控件后面,用户无法与之交互。

在这种情况下,如何将建议框置于最前面?

英文:

I have a ListView that serves as a suggestion box to an Entry.

The UI is organized on a grid, the ListView is hidden when there are no suggestions and for practical reasons I want the ListView declaration next to the Entry. But that means that its added to the grid before the control that is declared later on the same position as the suggestion box so it gets behind that control and the user cant interact with it.

How can I bring the suggestion box to the front in such situations?

答案1

得分: 0

你可以使用 ZIndex 属性来改变控件在 z 轴上的顺序。

所有继承自 IView 接口的控件都具有这个属性。具有更高 ZIndex 值的控件将位于其他控件之上。

这是一个示例,演示如何设置 ZIndex 属性,以使建议框位于稍后添加的 "Other Control" 之上。

在 XAML 中:

<Entry />
<ListView 
     Grid.Row="1"
     ZIndex="1"/>
<OtherControl Grid.Row="1" />

在 C# 中:

grid.Add(new Entry());
grid.Add(new ListView() { ZIndex = 1 }, row:1);
grid.Add(new OtherControl(), row: 1);

请注意,上述示例假定至少有两行的 Grid

英文:

You can use the ZIndex property to change the order of controls on the z-axis.

All controls that inherit from the IView interface have it. A control with a higher ZIndex value will be placed above others.

Here’s an example of how you could set the ZIndex property to keep the suggestion box on top of the "Other Control" that is added later.

In XAML :

&lt;Entry /&gt;
&lt;ListView 
     Grid.Row=&quot;1&quot;
     ZIndex=&quot;1&quot;/&gt;
&lt;OtherControl Grid.Row=&quot;1&quot; /&gt;

In C#:

grid.Add(new Entry());
grid.Add(new ListView() { ZIndex = 1 }, row:1);
grid.Add(new OtherControl(), row: 1);

Note the above assumes there is a Grid with at least two rows.

huangapple
  • 本文由 发表于 2023年5月7日 19:10:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193554.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定