locked
How To Judge a Control in ScrollViewer Viewerport RRS feed

  • Question

  • hi,

    How To Judge a Control in ScrollViewer Viewerport?

     

    and other question,

    if there are lots of user control  in ScrollViewer,

     

    How can I improve scrolling performance?


    for example,so  slowly。

     

    <Window x:Class="LotsOf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="300" Width="300"
        Loaded="Window_Loaded">
      <Grid>
        <ListBox x:Name="HelloKitty">
          <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
              <VirtualizingStackPanel></VirtualizingStackPanel>
            </ItemsPanelTemplate>
          </ListBox.ItemsPanel>
          <ListBox.ItemTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
            </DataTemplate>
          </ListBox.ItemTemplate>
        </ListBox>
      </Grid>
    </Window>
    using System.Windows;
    using System.Windows.Media;
    
    namespace LotsOf
    {
      /// <summary>
      /// Interaction logic for MainWindow.xaml
      /// </summary>
      public partial class MainWindow : Window
      {
        public MainWindow()
        {
          InitializeComponent();
        }
    
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
          HelloKitty.ItemsSource = Fonts.SystemFontFamilies;
        }
      }
    }

    Friday, November 19, 2010 4:05 PM

Answers

  • Hi 野老,

    We have spent some time on testing the Listbox performance and related Binding issue. And also I noticed you have posted a thread here http://social.microsoft.com/Forums/zh-CN/wpfzhchs/thread/fc517c77-c9bd-494b-8756-7ac846af61ca on which my colleague is helping you.

    As a general conclusion, it seems that the performance issue may mainly caused by your Hardware environment. Here is an article for you to test your WPF application performance http://msdn.microsoft.com/en-us/library/aa970683.aspx, note that the Hardware environment is a 2.8 GHz PC with 512 RAM and an ATI Radeon 9700 graphics card.

    In order to build responsive application on low level HW, you need to reduce system complexity of your app, lighten the CPU workload. Taking advantage of Hardware acceleration may enhance the performance in a notable way. As mentioned by my colleague in the other thread, in WPF 4.0 there is a new feature BitmapCache. You may also leverage this to improve your app.

    Since the performance bottleneck is your hardware, please be aware of that.

    Thank you, Have a good day!

     

    Best regards,

    Yves

     


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by 野老 Monday, November 29, 2010 9:04 AM
    Monday, November 29, 2010 3:53 AM

All replies

  • hello world
    Saturday, November 20, 2010 5:18 AM
  • Hi 野老,

    Welcome to MSDN forum!

    1. How To Judge a Control in ScrollViewer Viewerport?

    In ScrollViewer you may compare the value of  ViewportHeight  and ViewportWidth with the Control Bounds.

    For example, code below show how to determine if a Control is in ViewPort of ScrollViewer,

     

    Rect bounds = control.TransformToAncestor(scrollViewer).TransformBounds(new Rect(0.0, 0.0, control.ActualWidth, control.ActualHeight));
    Rect rect = new Rect(0.0, 0.0, scrollViewer.ViewportWidth, scrollViewer.ViewportHeight);
    bool bIsVisible = rect.Contains(bounds.TopLeft) || rect.Contains(bounds.BottomRight);

     

    2. How can I improve scrolling performance?

    You may specify the VirtualizingStackPanel. VirtualizationMode Attached Property as "Recycling" to achieve good performance in VirtualizingStackPanel.

    For more information please refer to

    http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.virtualizationmode.aspx

    Hope it helps! If you still have any doubts or questions please feel free to let me know.

     

    Best regards,

    Yves


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Edited by Yves.Z Tuesday, November 23, 2010 4:26 PM
    Tuesday, November 23, 2010 12:59 PM
  • VirtualizingStackPanel.VirtualizationMode is not the key,i  already setted it.
    Tuesday, November 23, 2010 3:55 PM
  • Hi 野老,

    We have spent some time on testing the Listbox performance and related Binding issue. And also I noticed you have posted a thread here http://social.microsoft.com/Forums/zh-CN/wpfzhchs/thread/fc517c77-c9bd-494b-8756-7ac846af61ca on which my colleague is helping you.

    As a general conclusion, it seems that the performance issue may mainly caused by your Hardware environment. Here is an article for you to test your WPF application performance http://msdn.microsoft.com/en-us/library/aa970683.aspx, note that the Hardware environment is a 2.8 GHz PC with 512 RAM and an ATI Radeon 9700 graphics card.

    In order to build responsive application on low level HW, you need to reduce system complexity of your app, lighten the CPU workload. Taking advantage of Hardware acceleration may enhance the performance in a notable way. As mentioned by my colleague in the other thread, in WPF 4.0 there is a new feature BitmapCache. You may also leverage this to improve your app.

    Since the performance bottleneck is your hardware, please be aware of that.

    Thank you, Have a good day!

     

    Best regards,

    Yves

     


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by 野老 Monday, November 29, 2010 9:04 AM
    Monday, November 29, 2010 3:53 AM
  •  

    Thank you for your help, I tried WPF 4, it works well. Did not reach the expected value, but has been acceptable within the. Thank you.

     

     

    Monday, November 29, 2010 9:04 AM