简体   繁体   English

以Xamarin形式访问控件内部的控件

[英]Accessing Controls inside Controls in Xamarin Forms

I am writing an app using Xamarin forms and I have an issue where I cannot access one of my controls so I am hoping someone can explain to me how to solve my issue. 我正在使用Xamarin表单编写应用程序,但遇到一个无法访问我的控件之一的问题,因此我希望有人可以向我解释如何解决我的问题。

Lets say I have 2 controls - 1 ListView & 1 Picker 可以说我有2个控件-1个ListView和1个选择器

<Picker x:Name="picker">
...
</Picker>

<ListView x:Name="listView">
...
</ListView>

If I want to access either of these controls from my code-behind, I can just use the names "picker" & "listView" and I find these fine. 如果我想从我的后台代码访问这些控件中的任何一个,则可以只使用名称“ picker”和“ listView”,然后发现它们很好。

If however the Picker is inside the ListView: 但是,如果选择器在ListView中:

<ListView x:Name="listView">
    <Picker x:Name="picker">
    ...
    </Picker>
</ListView>

In this scenario, I am able to see the "listView" control but I cannot see the "picker" control. 在这种情况下,我能够看到“ listView”控件,但是看不到“ picker”控件。

What can I do to access the Picker control when it is inside the ListView control? 当Picker控件位于ListView控件内部时,该怎么办?

I've managed to solve this issue by sending a reference of the "picker" as a CommandParameter. 我设法通过将“ picker”的引用作为CommandParameter发送来解决了此问题。

I can then access the relevant Picker based on the Index of the ListView. 然后,我可以基于ListView的索引访问相关的选择器。

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

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