How to use converter with community toolkit pop up

Brenda 60 Reputation points
2023-06-13T10:09:44.0566667+00:00

I have this popup where I want to change the colour of the tag when it is selected. Created a converter and when I used it in the xaml file it shows an error.

This works with regular page

<ContentPage.Resources>
  <converter:ColorTagConverter x:Key="ColorTagConverter" />
</ContentPage.Resources>

But with toolkit:popup it does not. I get the error

Error XLS0415: The attachable property 'Resources' was not found in type 'Popup'.

<toolkit:Popup.Resources>
  <converter:ColorTagConverter x:Key="ColorTagConverter" />
</toolkit:Popup.Resources>

Is there possible way to add this?

Thanks!

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,808 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 78,351 Reputation points Microsoft Vendor
    2023-06-14T02:38:12.9933333+00:00

    Hello,

    Is there possible way to add this?

    Yes, you can add Converter directly by Binding.Converter tag without using <toolkit:Popup.Resources> like following code.

    <toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui" 
                ...
                 >
      
        <VerticalStackLayout>      
                <Switch x:Name="switch2" />
                <Label>
                    <Label.Text>
                        <Binding Source="{x:Reference switch2}"
                                 Path="IsToggled">
                            <Binding.Converter>
                                <local:BoolToObjectConverter x:TypeArguments="x:String"
                                                             TrueObject="Yes"
                                                             FalseObject="No" />
                            </Binding.Converter>
                        </Binding>
                    </Label.Text>
                    <Label.TextColor>
                        <Binding Source="{x:Reference switch2}"
                                 Path="IsToggled">
                            <Binding.Converter>
                                <local:BoolToObjectConverter x:TypeArguments="Color"
                                                             TrueObject="Green"
                                                             FalseObject="Red" />
                            </Binding.Converter>
                        </Binding>
                    </Label.TextColor>
                </Label>
           
        </VerticalStackLayout>
    </toolkit:Popup>
    
    

    Here is a document about Binding value converters - .NET MAUI | Microsoft Learn

    If you want to add resources by toolkit:Popup.Resources , please add feature request in MAUI community toolkit GitHub page.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.