What does it mean to use a compiled binding?

TS44 81 Reputation points
2020-12-02T05:01:52.527+00:00

Use compiled bindings
Compiled bindings improve data binding performance in Xamarin.Forms applications by resolving binding expressions at compile time, rather than at runtime with reflection. Compiling a binding expression generates compiled code that typically resolves a binding 8-20 times quicker than using a classic binding. For more information, see Compiled Bindings.

I said, but I don't know how to do it.

Please tell me how to write in xaml and cs

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Alessandro Caliaro 4,196 Reputation points
    2020-12-02T06:53:50.327+00:00

    Hi @TS44

    You have to set this in your App.xaml.cs

    using Xamarin.Forms.Xaml;

    ...  
    [assembly: XamlCompilation (XamlCompilationOptions.Compile)]  
    namespace mynamespace  
    {  
      ...  
    }  
    

    then you have to Use the x:DataType attribute to provide the data type of the binding context of a VisualElement.

    for example:

    <ContentPage  
        xmlns="http://xamarin.com/schemas/2014/forms"  
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
        xmlns:viewmodels="clr-namespace:mynamespace"  
        x:Class="mynamespace.MainPage"  
        x:DataType="{x:Type viewmodels:MyPageViewModel}">  
      
        <ContentPage.BindingContext>  
            <viewmodels:MyPageViewModel />  
        </ContentPage.BindingContext>  
          
        <Label Text="{Binding MyValue}" />  
          
    </ContentPage>  
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. mc 5,471 Reputation points
    2020-12-02T05:21:17.993+00:00

    Just add

    [assembly:XamlCompilation(XamlCompilationOptions.Compile)]
    namespace xxxx{
    
    }
    

    will open the compiled binding.

    and in xaml you should tell the xaml which to check.

    for details please check:
    https://www.youtube.com/watch?v=q4EYysAgA9E

    0 comments No comments

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.