How to properly get element inside ControlTemplate in Native code
Posted: 06 Dec 2024, 22:50
Hello,
In XAML I have construction like this:
Then I'm trying to get this element by following code:
Here "component" receives nullptr. Also I've tried to call ApplyTemplate before getting child and also make child class with OnApplyTemplate callback that never called.
So how I can get ScrollViewer element from this template?
Also is it possible than scroll this ScrollViewer to needed row considering that I'm using virtualization for it?
Thank you!
In XAML I have construction like this:
Code: Select all
<Grid Grid.Row="1" Grid.Column="1">
<ItemsControl x:Name="MyGrid" ItemsSource="{Binding MyList}" ItemTemplate="{DynamicResource MyRow}" Grid.Row="1" Grid.Column="1" VirtualizingPanel.ScrollUnit="Pixel" VirtualizingPanel.CacheLengthUnit="Item" >
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer x:Name="MyScroll" CanContentScroll="True" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" Template="{StaticResource Template.ScrollViewer}" PanningMode="VerticalOnly" Focusable="False" >
<VirtualizingStackPanel IsItemsHost="True" />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
</Grid>
Code: Select all
Noesis::ItemsControl* myGridControl = uiControl->FindName<Noesis::ItemsControl>("MyGrid");
//m_myGridControl->ApplyTemplate();
Noesis::BaseComponent* component = myGridControl->GetTemplateChild("MyScroll");
So how I can get ScrollViewer element from this template?
Also is it possible than scroll this ScrollViewer to needed row considering that I'm using virtualization for it?
Thank you!