Make sure you add a Name and a FieldModifier attributes (from the http://schemas.microsoft.com/winfx/2006/xaml
namespace, usually named "x") to the element you want to access, something like this:
<TextBlock
x:Name="MyText"
x:FieldModifier="public"
Text="{Binding SomeValue}"
Style="{ThemeResource SubtitleTextBlockStyle}"
/>
This will instruct the behind-the-scene-generator to generate a named item in your class and make it public
in target language (here C#). This is an extract of the generated code:
partial class MainWindow : global::Microsoft.UI.Xaml.Window
{
...
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler", " 1.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent()
{
...
}
...
public global::Microsoft.UI.Xaml.Controls.TextBlock MyText;
...
}
Now, if you have an instance of MainWindow, you can call its members.