Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add content from C# to XAML

I have used a litle XamarinForms before and then i did a
naming to be able to point the c# code to it.

   <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   x:Class="MauiTest.MainPage"
   BackgroundColor="{DynamicResource SecondaryColor}">

    <StackLayout x:name="_stacklayoutname">     
    <Label Text="" x:Name="_Lable"/>
    </StackLayout>
</ContentPage>

And then i did like this in the MainPage.xaml.cs

   public MainPage()
    {
        InitializeComponent();
        _stacklayoutname.Children.Add(new Label { Text = "TEST" });
        _Lable.Text = "TEST";
    }

now it get this, but i can change the _Lable to "Text".
how can i point to a stacklayout.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Severity    Code    Description Project File    Line    Suppression State
Error   CS0103  The name '_stacklayoutname' does not exist in the current context   MauiTest (net6.0-android), MauiTest (net6.0-ios), MauiTest (net6.0-maccatalyst), MauiTest (net6.0-windows10.0.19041)    *** 11  Active

>Solution :

this is wrong

<StackLayout x:name="_stacklayoutname">  

it should be

<StackLayout x:Name="_stacklayoutname">  
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading