0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MAUI Tips - WinUIのPickerの挙動

Posted at

概要

これまでXamarin.Formsで作っていたアプリを、一念発起してMAUIで作り直す中で
調べたことの備忘録。

環境

Visual Studio 2022
MAUI
.NET 7

問題となった現象

Visual Studio for MACでiOS / Android向けに開発してきたスマホアプリを
Windows上でも動作させられないかと相談があり、
WindowsのVisual Studio 2022でコンパイルして実行してみたんですが、
Pickerの表示がおかしい・・・。
Windows上だと、なぜかPickerに値が表示されない・・・。
image.png

ちなみに、XAML上ではPickerをこのように記述。

                    <Picker x:Name="PrimaryItem"
                            Margin="30,0,20,10"
                            SelectedIndexChanged="PrimaryItem_SelectedIndexChanged"/>

コード内でPickerにデータを突っ込んでいるんですが、
そのコードはこんな感じ。

            PrimaryItem.Items.Add("加工");
            PrimaryItem.Items.Add("仕上げ");

解析結果

以下のMicrosoftのサイトに記載のサンプルコードをXAML上に記述しても表示されませんでした。
https://learn.microsoft.com/ja-jp/dotnet/maui/user-interface/controls/picker?view=net-maui-7.0#add-data-to-the-items-collection

<Picker Title="Select a monkey">
  <Picker.Items>
    <x:String>Baboon</x:String>
    <x:String>Capuchin Monkey</x:String>
    <x:String>Blue Monkey</x:String>
    <x:String>Squirrel Monkey</x:String>
    <x:String>Golden Lion Tamarin</x:String>
    <x:String>Howler Monkey</x:String>
    <x:String>Japanese Macaque</x:String>
  </Picker.Items>
</Picker>

どうやら、(Windows向けにビルドした場合では)PickerのItemsプロパティにデータを入れても、それらがPicker上に表示されない模様・・・。

ItemsSourceプロパティに設定した場合は表示されるので、
そちらに入れろってことなのかな・・・。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?