简体   繁体   中英

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.

Lets say I have 2 controls - 1 ListView & 1 Picker

<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.

If however the Picker is inside the 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.

What can I do to access the Picker control when it is inside the ListView control?

I've managed to solve this issue by sending a reference of the "picker" as a CommandParameter.

I can then access the relevant Picker based on the Index of the ListView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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