I used one view within another in this order. ScrollView; StakPanel two listViews; GridHere, I inserted a pressEvent to change the listviewBackground image, because for some reason I don't know why, when I used pressEvent and releaseEvent in the listview, they were never fired; so if anyone knows why please answer. This solution has another problem: When I scroll my list vertically, the item in the ListView is also clicked and my image is changed. To solve this problem, I am thinking of creating the ViewChanged and ViewChanging of the scrolling view, if my view is scrolled vertically the events will be fired. So by changing the "IsItemClickEnabled =" False "flag, which just makes scrolling work. Then, in the ViewChanged event, the flag is changed back to IsItemClickEnabled =" True ", My question is: is there a better way to solve this problem? Why pressed event does not work in ListView?
![Left Item unclicked Right Item Clicked][1]: https://i.stack.imgur.com/7uCLb.png
<?xml version="1.0" encoding="UTF-8"?>
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="IHM.UWP.Views.UserLogin.UserLoginView.ListUsersView" mc:Ignorable="d" Height="1300" Width="900">
<Page.Background>
<AcrylicBrush TintColor="#FF4DF7F7" TintOpacity="0.2" Opacity="0.3" />
</Page.Background>
<Page.Resources>
<DataTemplate x:Name="UsersViewTemplate">
<Grid x:Name="grdListEmployers" Margin="15,15,0,0" IsTapEnabled="False" PointerPressed="grdListEmployers_PointerPressed" IsDoubleTapEnabled="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHoldingEnabled="True" TabFocusNavigation="Cycle" ScrollViewer.VerticalScrollMode="Enabled">
<Grid.Background>
<ImageBrush />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="1" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image x:Name="b" Source="{Binding BackgroungImage }" Grid.Column="0" Grid.ColumnSpan="3">
<interactivity:Interaction.Behaviors>
<behaviors:Fade x:Name="Fade" Value="0.5" Duration="10000" Delay="18000" />
</interactivity:Interaction.Behaviors>
</Image>
<!--<Border CornerRadius="5"
BorderThickness="2" BorderBrush="LightGray" Margin="5"
Grid.Row="0"
Height="60"
Width="400"
Grid.Column="0"
Grid.ColumnSpan="3">
<Border.Background>
<ImageBrush/>
</Border.Background>-->
<StackPanel>
<TextBlock Text="{Binding Post}" Style="{ThemeResource BaseTextBlockStyle}" Margin="155,50,0,0" Foreground="Yellow" FontFamily="Courier Prime Code" />
<TextBlock Text="{Binding Nome}" Style="{ThemeResource BodyTextBlockStyle}" Margin="155,0,0,0" Foreground="White" FontSize="20" FontWeight="Bold" FontFamily="Courier Prime Code" />
</StackPanel>
<!--</Border>-->
<!--Height="120"
Width="120"
VerticalAlignment="Stretch"
HorizontalAlignment="Left"
Stretch="UniformToFill" FocusVisualPrimaryBrush="#FF231818" FocusVisualSecondaryBrush="Black">
<Ellipse.RenderTransform>
<TranslateTransform Y="-0" X="28">
</TranslateTransform>-->
<Ellipse x:Name="Ellipse" Grid.Row="0" Grid.Column="0" Height="120" Width="120" VerticalAlignment="Stretch" HorizontalAlignment="Left" Stretch="UniformToFill" FocusVisualPrimaryBrush="#FF231818" FocusVisualSecondaryBrush="Black">
<Ellipse.RenderTransform>
<TranslateTransform Y="0" X="28" />
</Ellipse.RenderTransform>
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding Photo}">
<ImageBrush.Transform>
<ScaleTransform ScaleX="0.9" ScaleY="0.9" CenterX="20" CenterY="59" />
</ImageBrush.Transform>
</ImageBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
</DataTemplate>
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1780" />
</Grid.RowDefinitions>
<!--<StackPanel Height="69" Width="892" Grid.ColumnSpan="2" Grid.Row="0">
<StackPanel.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color=" #808080" Offset="0.0" />
<GradientStop Color="#DCDCDC" Offset="0.25" />
<GradientStop Color="#A9A9A9" Offset="0.75" />
</LinearGradientBrush>
</StackPanel.Background>
<TextBlock Text="Usuário" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="27,0,0,0" FontFamily="Courier Prime Code"/>
</StackPanel>-->
<ScrollViewer VerticalScrollMode="Enabled" HorizontalScrollMode="Disabled" HorizontalAlignment="Center" VerticalAlignment="Top" Height="1300" Grid.ColumnSpan="2" Grid.Row="0" VerticalScrollBarVisibility="Hidden" IsTapEnabled="False" ViewChanging="ScrollViewer_ViewChanging" ViewChanged="ScrollViewer_ViewChanged">
<ScrollViewer.Background>
<SolidColorBrush Color="Aquamarine" Opacity="0.05" />
</ScrollViewer.Background>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,0" Width="1400" VerticalAlignment="Top" IsTapEnabled="False" IsHoldingEnabled="False" IsDoubleTapEnabled="False">
<!--<StackPanel.Background>
<SolidColorBrush Color="Aquamarine" Opacity="0.05"></SolidColorBrush>
</StackPanel.Background>-->
<ListView x:Name="MasterListView" ItemsSource="{x:Bind userViewModel.user1}" ScrollViewer.VerticalScrollMode="Disabled" ScrollViewer.HorizontalScrollMode="Disabled" SelectionMode="None" ScrollViewer.VerticalScrollBarVisibility="Hidden" IsTapEnabled="False" ShowsScrollingPlaceholders="False" ItemTemplate="{StaticResource UsersViewTemplate}" IsDoubleTapEnabled="False" IsItemClickEnabled="False" VerticalAlignment="Top" IsFocusEngagementEnabled="False" IsHoldingEnabled="False" IsTabStop="False" HorizontalAlignment="Left" IsMultiSelectCheckBoxEnabled="False" TabFocusNavigation="Once" FocusVisualPrimaryBrush="{x:Null}" FocusVisualSecondaryBrush="{x:Null}" />
<ListView x:Name="MasterListView2" ItemsSource="{x:Bind userViewModel.user2}" SelectionMode="None" ScrollViewer.VerticalScrollMode="Disabled" ScrollViewer.HorizontalScrollMode="Disabled" IsItemClickEnabled="False" ShowsScrollingPlaceholders="False" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemTemplate="{StaticResource UsersViewTemplate}" VerticalAlignment="Top" HorizontalAlignment="Right" IsMultiSelectCheckBoxEnabled="False" IsZoomedInView="False" IsTapEnabled="False" IsRightTapEnabled="False" IsHoldingEnabled="False" IsDoubleTapEnabled="False" />
</StackPanel>
</ScrollViewer>
</Grid>
</Page>
{
private void grdListEmployers_PointerPressed(object sender, PointerRoutedEventArgs e)
{
//Here I change image;
}
private void ScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
{
//Here I disable IsItemClicked at ListView
}
private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
//Here I enable IsItemClicked at ListView
}
About your pressEvent, do you mean the PointerPressed event in grdListEmployers doesn't be triggered? You set the IsTapEnabled in grdListEmployers to false, so the event won't be triggered, you need to set it to true, like:
About your second issue, do you mean when you scroll your listView, you don't want the item in the ListView can be clicked? If yes, you can detect if the scrollview finished scrolling in the ViewChanged event.