goofyui
goofyui

Reputation: 3492

How to access the variable declared in the xaml designer page?

In my page.xaml has the declaration as follows

<Label Text="Location" Style="{StaticResource labelStyle}" />
<ContentView Style="{StaticResource fieldView}">
    <Label Text="{Binding Title}" Style="{StaticResource fieldStyle}" />
</ContentView>

I am trying to access the variable Location.Text in xaml.cs page. However, I couldn't access the syntax.

Upvotes: 0

Views: 171

Answers (1)

Jason
Jason

Reputation: 89204

You need to assign a name to an element to access it from the code behind:

in the XAML:

<Label x:Name="txtLoc" Text="Location" Style="{StaticResource labelStyle}" />

in the code behind:

var loc = txtLoc.Text;

Upvotes: 1

Related Questions