最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

maui - FindByName in ContentView.ControlTemplate - Stack Overflow

programmeradmin6浏览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

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
Add a comment  | 

1 Answer 1

Reset to default 0

I think I get it from OnApplyTemplate, in the code behind like this one:

protected override void OnApplyTemplate()
{
    base.OnApplyTemplate();
    scrollbar = GetTemplateChild("Scrollbar") as Border;   
}
发布评论

评论列表(0)

  1. 暂无评论