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')

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,596 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
814 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 44,011 Reputation points Microsoft Vendor
    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 4,610 Reputation points Microsoft Employee
    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.