Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF ListView with DataTemplateSelector: PropertyChanged always sets focus to ListView
    primarykey
    data
    text
    <p>i'm really frustrated with this problem, but maybe it is really trivial and i just can't see where the problem is. The situation is the following: I have a ListView that is bound to an ItemsSource. Depending on the type, the DataTemplateSelector decides which template to use.</p> <p>If i tab through the controls (textboxes) everything works fine. as soon as i enter a value in a textbox and tab out of the textbox propertychanged for this property gets called. my controls get updated. That all is working fine, but here comes the problem: While the controls get updated, the focus does not move to the next tabstop but jumps to the ListView. How can i disable that? How can i get it to move the focus like no data has been entered and property changed has not been raised?</p> <p>Thanks in advance</p> <p>Update: Part of the XAML, if you need further information please let me know</p> <p><strong>Update2:</strong> After setting Focusable=false on the ListView the focus now jumps out of the whole ListView control if PropertyChanged is raised</p> <p>ListView declaration:</p> <pre><code>&lt;ListView x:Name="ListViewFields" KeyboardNavigation.TabNavigation="Cycle" KeyboardNavigation.IsTabStop="False" ItemsSource="{Binding Path=Fields}" ItemTemplateSelector="{StaticResource ControlDataTemplateSelector}" ItemContainerStyle="{StaticResource ListViewItemStyle}" Template="{StaticResource listViewTemplate}" Grid.IsSharedSizeScope="true"&gt; &lt;/ListView&gt; </code></pre> <p>Example of an Template:</p> <pre><code>&lt;DataTemplate x:Key="singleLineOfTextTemplate"&gt; &lt;Grid Style="{StaticResource GridStyle}"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition SharedSizeGroup="MyFirstColumn" /&gt; &lt;ColumnDefinition SharedSizeGroup="MySecondColumn" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Grid.Column="0" IsTabStop="False" Content="{Binding Path=Name}" /&gt; &lt;TextBox Grid.Column="1" x:Name="inputControl" IsTabStop="True" Text="{Binding Path=Value, Mode=TwoWay}" MinWidth="150"/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; </code></pre> <p><strong>Update 3:</strong> In the focus lost event of the ListViewItems I can see that focus is sometimes set to the DisconnectedItem (see <a href="https://stackoverflow.com/questions/14282894/wpf-listbox-virtualization-creates-disconnecteditems">DisconnectedItem on SO</a>, may be this is a reason why I have this behavior.</p> <p>I fixed my issue now by restoring the focus manually. In the ListViewItem GotFocus and LostFocus Events I store the selected ListViewItem and set a flag if restoring focus is neccessary, which then can be done in the ItemContainerGenerator.StatusChanged event.</p> <p>This solution seems very ugly to me - any other suggestions or ways to fix this would still be nice.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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