Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms XAML binding to x:String

Is there a way to dynamicaly assign Picker.Items from XAML?

Something like:

<Picker x:Name="pckTheme">
    <Picker.Items>
        <x:String>{Binding Option1Text}></x:String>
        <x:String>{DynamicResource Option2Text}></x:String>
    </Picker.Items>
</Picker>

(This sample is not working, of course).

As far as I can tell, the only allowed type in Picker.Items is x:String and I can't seem to find any method to bind to x:String.

Doing it from code is relatively simple, but I would prefer doing it from XAML directly, if possible.

Goal here is to localize content from resource file, but other uses may come handy.

like image 525
bocko Avatar asked Oct 16 '25 16:10

bocko


1 Answers

Please use the following XAML code:

<x:Array Type="{x:Type x:String}">
<x:Static Member="local:AppResources.Events"/>
<x:Static Member="local:AppResources.Device"/>
<x:Static Member="local:AppResources.Biographical"/>
</x:Array>

Where local is:

xmlns:local="clr-namespace:YOURNAMESPACE"
like image 168
DigitApps Avatar answered Oct 18 '25 11:10

DigitApps



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!