Is it possible to find element in <ContentView.ControlTemplate>
by FindByName
in this example:
<ContentView.ControlTemplate>
<ControlTemplate x:Name="ControlTemplateName">
<Grid>
<Border x:Name="Scrollbar"/>
</Grid>
</ControlTemplate>
</ContentView.ControlTemplate>
Everytime I received null when I try to get Scrollbar reference by this.FindByName<Border>("Scrollbar")
, but I can get reference to ControlTemplate by this.FindByName<ControlTemplate>("ControlTemplateName")
Edit: I am using maui 9.0
Is it possible to find element in <ContentView.ControlTemplate>
by FindByName
in this example:
<ContentView.ControlTemplate>
<ControlTemplate x:Name="ControlTemplateName">
<Grid>
<Border x:Name="Scrollbar"/>
</Grid>
</ControlTemplate>
</ContentView.ControlTemplate>
Everytime I received null when I try to get Scrollbar reference by this.FindByName<Border>("Scrollbar")
, but I can get reference to ControlTemplate by this.FindByName<ControlTemplate>("ControlTemplateName")
Edit: I am using maui 9.0
Share Improve this question edited Mar 25 at 13:25 infinitesimal asked Mar 25 at 13:04 infinitesimalinfinitesimal 4527 silver badges20 bronze badges 3- What is your end goal with this, what are you trying to achieve with FindByName – FreakyAli Commented Mar 25 at 13:25
- I need to get the Border reference and set its TranslationY. – infinitesimal Commented Mar 25 at 13:27
- Why can you not use a Binding for this? – FreakyAli Commented Mar 26 at 2:00
1 Answer
Reset to default 0I think I get it from OnApplyTemplate, in the code behind like this one:
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
scrollbar = GetTemplateChild("Scrollbar") as Border;
}