Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Converters in my Net.Maui Toolkit.Popup?

I am using converters in my regular pages.

I add Currencies in the VM

public ObservableCollection<Currency> Currencies { get; set; } = new();
....

and then I use them in a picker like so:

<ContentPage.Resources>
        <ResourceDictionary>
            <model:CountryPickerConverter x:Key="CountryPickerConverter" />
            <model:CurrencyPickerConverter x:Key="CurrencyPickerConverter" />
            <toolkit:IsNotEqualConverter x:Key="IsNotEqualConverter" />
        </ResourceDictionary>
</ContentPage.Resources>

and then

<Picker
    Title="{x:Static res:AppRes.SelectCurrency}"
    ItemsSource ="{Binding Currencies}"
    ItemDisplayBinding ="{Binding ., Converter={StaticResource CurrencyPickerConverter}, Mode=TwoWay}"
    ..........
</Picker>

It works. But now I need to do the same thing in my toolkit:Popup object.

I am not able to write this section:

<toolkit:Popup.Resources>
        <ResourceDictionary>
            <model:CurrencyPickerConverter x:Key="CurrencyPickerConverter" />
        </ResourceDictionary>
</toolkit:Popup>

or something similar.

I did not find any example on how to do this. What is the correct syntax for this, please ? Is it at all possible ?

Thank you. Alex

like image 701
Alex Avatar asked Sep 14 '25 18:09

Alex


1 Answers

At the time of writing this, the <toolkit:Popup> does not have a Resources-attribute (yet). You may want to use the Resources-attribute on the first child element (container) of the actual popup instead. In my case it was a <frame> element:

<toolkit:Popup>
    <Frame>
        <Frame.Resources>
            <model:CurrencyPickerConverter x:Key="CurrencyPickerConverter" />
        </Frame.Resources>
    </Frame>
</toolkit:Popup>

You can then use the converter for any controls within the <Frame> element.

like image 190
Al John Avatar answered Sep 17 '25 20:09

Al John