2017-11-03 3 views
0

私はこのコードを持っている:Xamarinで要素名の配列を使用することはできますか?

<local:CustomTextCell x:Name="cfs0" /> 
<local:CustomTextCell x:Name="cfs1" />  
<local:CustomTextCell x:Name="cfs2" /> 

は、私が代わりにこれらの3人の名前を使用しての配列を使用することができる方法はありますか?

なぜなら、forループを使用してセルのプロパティを変更したいからです。

+3

は、このヘルプを行い、子細胞 – Ada

+0

を通じて親セクションに名前を追加し、ループ? https://docs.microsoft.com/en-us/dotnet/framework/xaml-services/x-array-markup-extension#xaml-values –

+0

私は解決策については何のクレジットも取りませんが、これはあなたが望むものだと思います... https://blog.pieeatingninjas.be/2017/04/20/trigger-propertychanged-of-indexed-property-in-xamarin-forms/ – Depechie

答えて

3

親にTableSectionという名前を付けて、すべてのセルにループすることができます。

<TableSection Title="Parent" x:Name="parentSection"> 
    <local:CustomTextCell x:Name="cfs0" /> 
    <local:CustomTextCell x:Name="cfs1" />  
    <local:CustomTextCell x:Name="cfs2" /> 
</TableSection> 

の追加は、次のような論理をループ:

foreach (CustomTextCell textCell in parentSection) 
{ 
    System.Diagnostics.Debug.WriteLine($"{textCell.Text} - {textCell.IsChecked}");  
}