Note that there are some explanatory texts on larger screens.

plurals
  1. POIrregular event behavior - firing dependent on subscription to child control's equivalent event
    text
    copied!<p>I encountered this behavior with WinRT's ListView.</p> <p><code>LayoutUpdated</code> event does fire less often if no event handler is attached to the inner <code>ScrollViewer</code>'s <code>LayoutUpdated</code> event.</p> <p>I marked the critical line near the bottom with <code>// === Critical line ===</code>. Removing the leading slashes will lead to <code>lv_LayoutUpdated</code> being called more often.</p> <p>This has implications since the event is fired far too seldom for it to be of any use to me (in the commented-out case) The problem is, that I cannot set the scroll position before the <code>ScrollViewer</code>'s mutation has come to an end. Routing through the <code>ScrollViewer</code>'s event seems silly, though.</p> <p>Is this a bug or is it explainable with bubbling strategies or sth.?</p> <p>EDIT: BTW, this page is not shown in the app's root frame, but in a frame of a different page if that makes any difference.</p> <p>EDIT2: I ended up disovering why the firing timing was useless (was doing the data binding async, which screwed with the standard event timings). The behavior persists, though - subscribing to <code>ScrollViewer</code>'s event leads to more publishing by the <code>ListView</code>'s event. Under what additional circumstances this ends up happening, I do not know. I am using Caliburn.Micro - so maybe their data source wiring does something to the control. E.g. one issue with CM is, that it swallows the first LayoutUpdated event of the view (if bound via Message:Attach atleast) - although this might only affect the view model.</p> <p>Anyway, I'll leave this question be for others to disover.</p> <p>This setup in the code-behind:</p> <pre><code> public FileListView() { this.InitializeComponent(); var lv = (ListView)FindName("Files"); lv.Loaded += lv_Loaded; lv.LayoutUpdated += lv_LayoutUpdated; } void lv_LayoutUpdated(object sender, object e) { var m = (FileListViewModel)DataContext; m.Offset = 100; } void lv_Loaded(object sender, RoutedEventArgs e) { var lv = (ListView)sender; var sv = lv.GetFirstDescendantOfType&lt;ScrollViewer&gt;(); if (sv == null) { return; } //sv.LayoutUpdated += sv_LayoutUpdated; // === Critical line === } void sv_LayoutUpdated(object sender, object e) { // No code here. Just the subscription suffices } </code></pre> <p>The XAML:</p> <pre><code> &lt;Page x:Class="Namespace1.FileListView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Poolar.Mobile.PsProject.WinRT.Views" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"&gt; &lt;Grid HorizontalAlignment="Left" Height="768" VerticalAlignment="Top" Width="1366"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="61*"/&gt; &lt;RowDefinition Height="707*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;ListView x:Name="Files" HorizontalAlignment="Left" Height="446" VerticalAlignment="Top" Width="1366" Margin="10,10,-10,0" Grid.Row="1" /&gt; &lt;Button x:Name="GoBack" x:Uid="ButtonGoBack" Content="Button" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/&gt; &lt;/Grid&gt; &lt;/Page&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload