Page 1 of 1

ScrollViewer in 2.2.0 Today's release

Posted: 15 Mar 2019, 10:59
by Khonan
Hi,

Updating to 2.2.0 today's release and I got the following behaviour :

ScrollViewer is responding to the mousewheel only if the mouse is over the ScrollViewer. Rolling mousewheel while over a child (listview) won't make it scroll anymore (Was working with the previous release)
           <Grid Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top">
                <ScrollViewer>
                    <StackPanel x:Name="itGridViewRight" VerticalAlignment="Top">
<ListView Grid.Row="1" x:Name="itListViewFiles" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ListView.ContextMenu>
                    <ContextMenu>
                        <MenuItem x:Name="itContextSelectAll" Header="Select All"></MenuItem>
                        <MenuItem x:Name="itContextUnselectAll" Header="UnSelect All"></MenuItem>
                    </ContextMenu>
                </ListView.ContextMenu>
                <ListView.View>
                    <GridView>
                        <GridView.ColumnHeaderContainerStyle>
                            <Style>
                                <Setter Property="FrameworkElement.Visibility"  Value="Collapsed"/>
                                <Setter Property="FrameworkElement.Height" Value="1"/>
                            </Style>
                        </GridView.ColumnHeaderContainerStyle>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox x:Name="itCheckBoxList" Margin="0" VerticalAlignment="Center" IsChecked="{Binding IsChecked}" Checked="OnCheck" Unchecked="OnCheck"></CheckBox>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="0" Text="{Binding Text}"></TextBlock>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Ellipse Fill="{Binding ColorBrush}" Width="20" Height="20" MouseEnter="Ellipse_MouseEnter" MouseLeave="Ellipse_MouseLeave" Stroke="#55FFFFFF" MouseLeftButtonDown="Ellipse_MouseLeftButtonDown" StrokeThickness="1">
                                    </Ellipse>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
                    </StackPanel>
                </ScrollViewer>
            </Grid>

Re: ScrollViewer in 2.2.0 Today's release

Posted: 15 Mar 2019, 12:17
by Khonan
Tried to hook the MouseWheel Event of the ListView
m_ListView.MouseWheel += MouseWheelToParentScrollViewer;
but it's never triggered... Might Explain..

Re: ScrollViewer in 2.2.0 Today's release

Posted: 15 Mar 2019, 12:34
by sfernandez
Hi, looking at the xaml I see the problem... as the inner ListView has no height limit, the outer ScrollViewer allows the list to grow as much as it needed, resulting in a ListView with nothing to scroll.

I just tested the following xaml in XamlPlayer 2.2.0 and it works as expected: if mouse is over inner ListBox control, then mouse wheel will scroll that list, if mouse is out of the ListBox, then mouse wheel will scroll the outer ScrollViewer.
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ScrollViewer Width="200" Height="200" FontSize="30" Background="Silver" Foreground="Black">
        <StackPanel>
            <TextBlock Text="Some text"/>
            <TextBlock Text="Some text"/>
            <TextBlock Text="Some text"/>
            <ListBox Margin="20,0" Height="100" FontSize="24" Background="WhiteSmoke">
                    <TextBlock Text="Inner text"/>
                    <Button Content="Button"/>
                    <TextBlock Text="Inner text"/>
                    <TextBlock Text="Inner text"/>
                    <TextBlock Text="Inner text"/>
                    <TextBlock Text="Inner text"/>
                    <TextBlock Text="Inner text"/>
                    <TextBlock Text="Inner text"/>
            </ListBox>
            <TextBlock Text="Some text"/>
            <TextBlock Text="Some text"/>
            <TextBlock Text="Some text"/>
            <TextBlock Text="Some text"/>
        </StackPanel>
    </ScrollViewer>
</Grid>
Can you make it work that way?

Re: ScrollViewer in 2.2.0 Today's release

Posted: 15 Mar 2019, 14:45
by Khonan
The Listview is not supposed to scroll but grow as much as needed.
What I was expecting is the outer ScrollViewer to scroll its content (And working that way prior 2.2.0) The ScrollViewer will have to scroll multiple "Expander" with ListView inside (with no height limit)
With 2.2.0 SwrollViewer don't get the MouseWheel event.

And if it wasn't the correct behaviour with 2.1 then I should be able to raise the event Mousewheel of the ScrollViewer from the ListView's MouseWheel but the MouseWheel delegate is not called in the listview
<Grid Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ScrollViewer>
                    <StackPanel x:Name="itGridViewRight" VerticalAlignment="Top">
                        <Grid  Width="400" ScrollViewer.VerticalScrollBarVisibility="Visible">
                            <Expander  Header="{StaticResource locCategories}" ExpandDirection="Down" IsExpanded="False">
                                <Grid>
                                    <ListBox x:Name="itListViewFiles" SelectionMode="Single">
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                        <TextBlock>ITEM ITEM</TextBlock>
                                    </ListBox>
                                </Grid>
                            </Expander>
                        </Grid>
                    </StackPanel>
                </ScrollViewer>
            </Grid>

Re: ScrollViewer in 2.2.0 Today's release

Posted: 15 Mar 2019, 15:07
by Khonan
Just made a test in a WPF app and I got the same behavior as 2.2.0.

itListViewFiles.MouseWheel += ItListViewFiles_MouseWheel; as the same effect with WPF too.

So it was working with 2.1 but it was luck :p

I'll post a work around here as soon I find.

Thanks for the help ;)

Re: ScrollViewer in 2.2.0 Today's release

Posted: 15 Mar 2019, 15:29
by Khonan
Found to make it in WPF :

Do not use ListView.MouseWheel but PreviewMouseWheel

Now I've to figure out how to translate "var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);" to Noesis and I'll be good.


 public MainWindow()
        {
            InitializeComponent();
            itListViewFiles.PreviewMouseWheel += ItListViewFiles_MouseWheel;
        }

        private void ItListViewFiles_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
            eventArg.RoutedEvent = UIElement.MouseWheelEvent;
            eventArg.Source = sender;
            itScrollViewer.RaiseEvent(eventArg);
        }
        

Re: ScrollViewer in 2.2.0 Today's release

Posted: 15 Mar 2019, 15:43
by Khonan
Solved,

PreviewMouseWheel is good :
            ListBox lv = (Noesis.ListBox)FindName("itListViewFiles");
            lv.PreviewMouseWheel += MouseWheelToParentScrollViewer;

Get the Parent ScrollViewer and raise the Mousewheel event for him:
        public void MouseWheelToParentScrollViewer(object sender, MouseWheelEventArgs e)
        {
            FrameworkElement t = sender as FrameworkElement;
            FrameworkElement parent = t.Parent as FrameworkElement;
            while (parent != null)
            {
                ScrollViewer scroll = parent as ScrollViewer;
                if (scroll != null)
                {
                    MouseWheelEventArgs eventArg = new MouseWheelEventArgs(scroll, UIElement.MouseWheelEvent, e.Delta);
                    scroll.RaiseEvent(eventArg);
                    return;
                }
                parent = parent.Parent as FrameworkElement;
            }
        }

My problem was Noesis Gui 2.2.0 is working much more like WPF :p

Thanks Mr SFernandez

Re: ScrollViewer in 2.2.0 Today's release

Posted: 16 Mar 2019, 08:29
by jsantos
Thanks for your feedback!