Replies: 2 comments 1 reply
-
Since the item is inside of a DataTemplate, it's usually more tricky to be able to reference it from code-behind. If it's a very simple change you need to have between something like a Wide and Narrow breakpoint, there's also the Respsonive Markup Extension that you can use instead of the full ResponseView with templates. So it could look something like: I have a sample project attached that demonstrates the difference XAML<Grid utu:SafeArea.Insets="VisibleBounds"
RowDefinitions="*,*">
<Grid Background="Red">
<utu:ResponsiveView HorizontalAlignment="Center"
VerticalAlignment="Center">
<utu:ResponsiveView.WideTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center"
x:Name="wideText"
Text="Wide!" />
</DataTemplate>
</utu:ResponsiveView.WideTemplate>
<utu:ResponsiveView.NarrowTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center"
x:Name="narrowText"
Text="Narrow!" />
</DataTemplate>
</utu:ResponsiveView.NarrowTemplate>
</utu:ResponsiveView>
</Grid>
<Grid Background="Green"
Grid.Row="1">
<TextBlock x:Name="myRespText"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{utu:Responsive Narrow='Narrow!', Wide='Wide!'}" />
</Grid>
</Grid> Code Behindpublic sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
var text = myRespText.Text;
// These don't work while in a DataTemplate
//var text2 = narrowText.Text;
//var text3 = wideText.Text;
}
} Recording.2025-04-13.101443.mp4 |
Beta Was this translation helpful? Give feedback.
-
data-templated content are not accessible via xName as an exposed local field/property |
Beta Was this translation helpful? Give feedback.
-
Question from community:
I have the following XAML (MainPage.xaml):
I can't reach
txtClaim
to change the Text property from code-behind, like:txtClaim.Text = "Text put from code behind.";
VS2022 states that txtClaim does not exist. What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions