How to bind a attached property in MAUI(XAML)?

尼龟 杰 190 Reputation points
2024-01-19T10:55:13.21+00:00

A simple label

<Label x:Name="llll" FontSize="16" extensions:CommandParameterHelper.Parameter="content" Text="{Binding Source=llll,Path=(extensions:CommandParameterHelper.Parameter),Mode=OneWay}"></Label> 


The value had setted,because I debugged and the method of GetParameter used by C# code worked,so I think it a binding error(ofcause it throw out 'not found (extensions:CommandParameterHelper on Label')

Developer technologies | .NET | .NET MAUI
Developer technologies | XAML
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-01-24T07:25:12.92+00:00

    Hello,

    I think it a binding error(ofcause it throw out 'not found (extensions:CommandParameterHelper on Label')

    The cause of this issue is a problem with how it is bound.

    This error occurs because CommandParameterHelper is a static class and is not part of this Label internal property. For static class properties, you need to bind them as follows:

    <Label x:Name="llll" FontSize="16"  Text="{Binding Source={StaticResource extensions:CommandParameterHelper},Path=Parameter}" />
    

    As a supplement, using attached properties as bindings is not a recommended use case. According to the official documentation, it is more convenient to use bindable properties.

    Best Regards,

    Alec Liu.


    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Pinaki Ghatak 5,600 Reputation points Microsoft Employee Volunteer Moderator
    2024-01-19T10:58:35.21+00:00

    Hello @尼龟 杰
    It seems like you are having trouble with a binding error in your XAML code. The error message you mentioned suggests that the extensions:CommandParameterHelper namespace is not found. You can try checking if the namespace is correctly defined and imported in your XAML file. Also, make sure that the assembly containing the CommandParameterHelper class is correctly referenced in your project. I hope this helps to solve your problems.


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.