はつねの日記

Kinect, Windows 10 UWP, Windows Azure, IoT, 電子工作

Xamarin Forms の ListView でコンテキストサイズを変更しても行の高さが更新されない

[EN]

Xamarin Forms ListView Row Height Does Not Update When Changing Context Size

I've been having trouble creating iOS apps in Xamarin. It is.

That's why, in ListView and elsewhere, you can increase the number of characters in each element, and so on, to make the content more interesting by repetition. The problem of keeping the height of the ListView rows the same when the height is dynamic is.
This only occurs on iOS and the same XAML definition, and the same code, but on Android. This does not happen.

 

The problem is that when displaying a list with different content heights in a ListView, the This is confused with the issue of not being height per content. This problem can be solved on iOS by setting it to true with the HasUnevenRows property. 

docs.microsoft.com But the problem is when each element seems to change after it's displayed. As far back as 2015 or so, we've been asking questions in stackoverflow and Xamarin's It existed as a GitHub issue. The following is a clear description of the issue.

 

github.com

A valid method of targeting that we are currently able to see is to add an ItemSource to the ListView's The idea is to execute the following two lines when the binding element is changed (on iOS, the Only!) 

            if (this.Parent is ListView list)
            {
                list.HasUnevenRows = !list.HasUnevenRows;
                list.HasUnevenRows = !list.HasUnevenRows;
            }

However, if you use this method, when you change the HasUnevenRows property and revert back to The entire ListView is flickering.

However, there is a bit of hope for solving this problem.

You can find this as a "To do-High impact" on GitHub at Xamarin.Forms The issue was posted 5 days ago on. 

github.com

f:id:hatsune_a:20200611080913p:plain

github.com

 I hope this will help you work things out.

 

[JP]

Xamarin Forms の ListView でコンテキストサイズを変更しても行の高さが更新されない

Xamarin.FormsでiOSアプリを作成しているときにずっと困っていることがあります。

それが、ListViewなどで、各要素の文字数を増やすなどして折返しによりコンテンツの高さがダイナミックに変わるようなときにListViewの行の高さが変わらないという問題です。

これは、iOSでのみ発生して同じXAML定義、そして同じコードでもAndroidでは発生しません。

 

この問題は、異なるコンテンツの高さをもったリストをListViewで表示したときにコンテンツごとの高さにならないという問題と混同されます。この問題はHasUnevenRowsプロパティとtrueにすればiOSでも解決します。

docs.microsoft.com

しかし、問題は表示した後に各要素が変化するようなときです。古くは2015年くらいからstackoverflowでの質問やXamarinのGitHubのissueとして存在しました。その中で、問題の説明がわかりやすいものが次のものです。

github.com

現在確認できている有効な対象方法は、ListViewのItemSourceにBindingしている要素に変更があったときに次の2行を実行することです(iOSのときだけ!)

            if (this.Parent is ListView list)
            {
                list.HasUnevenRows = !list.HasUnevenRows;
                list.HasUnevenRows = !list.HasUnevenRows;
            }

しかしこの方法を採用した場合、HasUnevenRowsプロパティを変更して戻すときにListView全体がちらついてしまいます。

しかし、この問題の解決に少しだけ希望があります。

Xamarin.FormsのGitHubで「To do-High impact」としてこの問題が5日前に掲載されました。

github.com

f:id:hatsune_a:20200611080913p:plain

github.com

これで解決に向かってくれるといいですね。