ListView Template with ScrollViewer containing custom Panel instantiated twice and ItemsOwner(this) returns null
Posted: 19 May 2020, 12:14
I have the following abbreviated XAML for displaying thumbnails on a filesystem. I specify a custom panel in the Template.
I can then find my customized Panel in code-behind like this:
But that Panel is not the one used by Noesis, since I can see that two are instantiated if I put a breakpoint on the Panel's constructor. The first is created when FileManagerView.xaml is loaded, second one is created when I call listView.UpdateLayout().
Also ItemsControl.ItemsOwner(this) from my panel returns null
I've tried several combinations of this per suggestions here but no luck:
https://stackoverflow.com/questions/285 ... emshost-do
Code: Select all
<UserControl x:Class="Modules.FileManager.FileManagerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
xmlns:local="clr-namespace:Modules.FileManager">
<UserControl.Resources>
<Style x:Key="FileManagerListViewStyle" TargetType="{x:Type ListView}">
<Setter Property="BorderBrush" Value="Black"></Setter>
<Setter Property="BorderThickness" Value="2"></Setter>
<Setter Property="Grid.IsSharedSizeScope" Value="True"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListView}">
<ScrollViewer ScrollChanged="OnScrollChanged" Margin="1" Style="{StaticResource StandardScrollViewer}" CanContentScroll="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" PanningMode="VerticalOnly" Focusable="false">
<local:VirtualizingTilePanel x:Name="tilePanel" IsItemsHost="True" ItemsPerRow="5" ItemsPerCol="3"></local:VirtualizingTilePanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid Background="{StaticResource ControlBackgroundBrush}">
<ListView
x:Name="CurrentDirectoryListView"
KeyDown="OnListViewKeyDown"
SelectionMode="Single"
Initialized="ListView_OnInitialized"
Loaded="ListView_OnLoaded"
Style="{StaticResource FileManagerListViewStyle}"
ItemContainerStyle="{StaticResource FileManagerListViewItemStyle}"
ItemsSource="{Binding CurrentDirectoryContents}">
<ListView.ItemTemplate>
<!-- lots of xaml -->
<ListView.ItemTemplate>
</ListView>
</Grid>
</UserControl>
Code: Select all
listView = (ListView)FindName("CurrentDirectoryListView") ?? throw new MemberAccessException("CurrentDirectoryListView");
virtualizingTilePanel = (VirtualizingTilePanel)listView.Template.FindName("tilePanel") ?? throw new MemberAccessException("tilePanel");
Also ItemsControl.ItemsOwner(this) from my panel returns null
Code: Select all
public class VirtualizingTilePanel : VirtualizingPanel, IScrollInfo
{
...
ItemsControl itemsControl = ItemsControl.GetItemsOwner(this); // This returns null
https://stackoverflow.com/questions/285 ... emshost-do