.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

ScrollViewer scales (almost) into infinity

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :WPF

Hi there,

I have a problem with a simple scrollviewer around a datagrid. I want the datagrid to fit to the window size, so I set the width of my datagrid columns to "*". See my code below:



<Window x:Class="ScrollViewerProblem.MainWindow"
 <Style TargetType="{x:Type DataGrid}">
  <Setter Property="ClipToBounds" Value="True" />
  <Setter Property="CanUserResizeRows" Value="False" />
  <Setter Property="CanUserReorderColumns" Value="False" />
  <Setter Property="CanUserAddRows" Value="False" />
  <Setter Property="AutoGenerateColumns" Value="False" />
  <Setter Property="SelectionMode" Value="Single" />
  <ColumnDefinition Width="*"/>
  <ColumnDefinition Width="3*"/>
 <TabControl Grid.Column="1">
  <TabItem Header="I am a TabItem">
  <ScrollViewer Vertica

View Complete Post

More Related Resource Links

Changing Mouse Cursor into Crossed Circle in ListBox-ScrollBar/ScrollViewer(on Drag and Drop).

Hi All,   I have a ListBox with 10 items, the automatic Scrollbar/ScrollViewer is appearing. If i'm dragging an item from the listbox and moving the mouse cursor on top scrollbar/scrollviewer the cusor have to change into CROSSED CIRCLE(means its not a location to drop). Can any one help to do the same, or please let me know if more info needed.   Thanks, Karthikeyan Manickam.

Minwidth with Scrollviewer to then take over

Morning Guys and Gals, I'm having trouble with my code (again) and I would like some help please. I am trying to get text that is in a groupbox to wrap until a minimum width and the a scrollviewer to take over when the miniumum width is reached. This is what I have so far to no avail. <Window x:Class="TextScrollviewer.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <TextBlock TextWrapping="Wrap" MinWidth="300">Some Loooooooooooooooooong amount of text for something that won't all fit nicely on the page and its annoying me that I can't fix it, please help!</TextBlock> </ScrollViewer> </Grid> </Window>   All help is greatly apreciated; if I've not made it clear enough what I would like please just leave a comment and I will try and explain it in a different way. Thanks in Advance Alex

Can anyone explain how SQL Server performance scales with CPUs/Cores, memory, disk drives, etc?

I have experienced the situation where our application running on an expensive system with two 4 core CPUs ran slower than on a cheap machine with one dual core CPU. Both machines had similar memory capacity. In each case, the same query was being run by only one user. It would be nice to find a way to increase performance, but if adding cores doesn't help, what can a poor developer do? Customers get annoyed when they spend a truckload of money on a new server and nothing changes... Another potential problem is when customers have an expensive SAN system Sometimes the performance is much slower then on a system with conventional storage. Can anyone explain the relationship between SQL Server perfomance and hardware ?

Weird Exception: Method not found: 'Double System.Windows.Controls.ScrollViewer.get_ContentHorizon

Hi guys I have an XBAP application that uses a Xamdatagrid from Infragistics. I have some filtering on this grid, that rebinds after a filter. The problem is, when a user has scrolled to a certain point and then filters, the rebinding causes the grid to scroll to the beginning position of the grid. Now how I solve this is by getting an instance of the ScrollViewer, I get the ScrollViewer.ContentHorizontalOffset and then I do a ScrollViewer.ScrollToHorizontalOffset after it filters.   Now here comes the problem. For 99% of the users of this xbap app, this will work absolutely fine. Most, if not all of the users run exactly the same machines, XP 64 bit with 8GB RAM. The other 1% get the error: Method not found: 'Double System.Windows.Controls.ScrollViewer.get_ContentHorizontalOffset()'. I cannot reproduce this error on my own box, our dev server or our production server, it is a phantom exception that only pops up on a certain condition. I have even wrapped the "offending" code in a try catch and it still doesn't solve it. If I set the DispatcherUnhandledExceptionArgs Handled to true, it works, but it doesn't feel right. How is this possible? If the method doesn't exist, how can it compile? Why does that method exist for 99% of the other users running the exact same machines? I have googled my fingers raw without any valid results and this issue is frustrat

How can I stop a WinFormsHosted control from scrolling over my ScrollViewer?

I have a WPF application where the main window contains a NavigatorFrame and a ScrollViewer, like so: <ScrollViewer x:Name="scrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" > <MainWindow:NavigatorFrame x:Name="navigatorFrame" Background="{StaticResource windowBackground}" IsTabStop="False" NavigationUIVisibility="Hidden" > .... </MainWindow:NavigatorFrame> </ScrollViewer> I use the NavigatorFrame to display WPF Pages, and one of the Pages contains two WinFormsHost controls that each contain a WinForms SyntaxEditor (from Actipro). Unfortunately, when I try to scroll using the ScrollViewer, the WinForms editors move above the scrollbars and overlap other controls in my application. When I remove the ScrollViewer, the SyntaxEditors go back to behaving (except their Page doesn't have scrollbars). My understanding is that WinFormsHosts have a ZOrder that causes them to appear over WPF elements, which may explain this issue. Nevertheless, I'm wondering if

Strange ScrollViewer Behavior



When i use the following code, my scrollviewer appears for both vertical and horizontal. however the up and down arrows, and the left right arrows appear back to back. these buttons work fine. they just look terrible. after all the down button should appear at the bottom of my grid.

Can anyone help me out.



Gary Rusher

<local:BooleanToColorConverter x:Key="BooleanToColorConverter"/>

    <DataTemplate x:Key="BasicComponent">
      <TextBlock Text="{Binding Path=Description}"
            Foreground="{Binding Path=Rendered,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource BooleanToColorConverter}}">
    <HierarchicalDataTemplate x:Key="ComplexComponent"
                 ItemsSource="{Binding Components}">

Multitouch with ScrollViewer


I have recently been experimenting with multi touch in WPF 4 and have managed to get something working using a combination of:






The problems start when I wrap the control being manipulated in a ScrollViewer and set PanningMode to Both.

I can pan the ScrollViewer around fine but all other manipulations like rotate and scale seem to be lost.

Is it just me or is there a problem here?



Invalid column name 'Infinity'. + SQLException


Hi All,

I am inserting the values to the table using the table adapter. And all columns except the datetime and messageid that is unique identification column are the varchar then also i am facing problem of "Invalid column name 'Infinity'. + SQLException".  StackTrace is as below:


   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean ret

How to sync a listview control to a scrollviewer


I have two apps, one winform and one WPF, which both use the same code.

On each I have a ListView control.  I have a routine that increments the .SelectedIndex by 1 and performs work on the data for that line in the ListView then goes on to the next.

The ListView control in the WinForm app has its own vert scrollbar and as the program changes the .SelectedIndex the selected line is highlighted and kept visable in the ListView.

In the WPF the ListView does not have its own scrollbar and I have to use a Scrollviewer.  This arrangement does not mimic the WinForm app.  As the ListView items are selected they are highlighted only as long as they are visible on the ListView box.  Once the SelectedItem is beyond teh visable portion of the ListView Control the ScrollViewer does not scroll down to keep it visable.

How do I sink them together so that the SelectedItem is always visable just like the WinForm app????

Binding a scrollviewer height


i'm using a stack of expanders to mimick an accordion control. I have an ItemsControl on the page with it's ItemsSource set to Screens. Here is some sample code for the ViewModel.

	internal class MainWindowViewModel
ObservableCollection<Expander> _screens = new ObservableCollection<Expander>();
public ObservableCollection<Expander> Screens { get { return _screens; } }

internal Dictionary<stringUserControl> AppScreens = new Dictionary<stringUserContr

Scrollviewer with elements that loop


1) Hi, I was wondering if there was a way to have a scrollviewer with elements that loop.


Let us say I have 4 items.

After scrolling from left to right you see something like this in order:

<item 1> <item 2> <item 3> <item 4> ... <item 1> <item 2>

Also currently I am using a StackPanel inside my scroller.

2) I also have another issue with scrollling... it seems when I click inbetween my images ( the items i have in my scroller), I cannot scroll. I have to directly click on the images to scroll.

3) Is there a way to snap these images whenever I scroll such that, the image closest to the center of the scroller will snap and enlarge in size.

Thanks for the tips :)

ScrollViewer problem


I've created two user controls, one creates me a row with labels and one creates me a row with TextBoxes (i'm trying to create something like dataGrid but with TextBoxes).

I put my users controls in a stackPanel, which is inside of a scrollViewer.

I'm having problems with two things:

1. I want that the scroll viewer will scroll only on the TextBox Rows, so the labels (which represent the headers) will always be visible.

I tried not to put them inside the scrollViewer, but then when I need to scroll Horizontally, the labels are not moving...

2. For some reason, the Horizontal scrollBar appears only when I'm adding the TextBox rows although I gave each TextBox the same width as it's label has.

Below you can find the relevant code:

Thanks a lot,


TextBox User Control:

<Grid x:Name ="weaponsDetailsGrid">
            <ColumnDefinition Width="3" />
            <ColumnDefinition Width="14" />
            <ColumnDefinition Width="2&

scrollviewer not working in nested User Control


The code below illustrates my problem: I cannot get the scrollbars in the embedded User Control (ucScroll1) to show up when I resize the main window (Window1) smaller.

It won't work even if I force the issue by defining it like this:
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" IsEnabled="True" >

<UserControl x:Class="ScrollViewerApp.ucScroll1"



 Height="100" Width="300">

 <StackPanel VerticalAlignment="Top">

  <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" >

   <StackPanel Background="Aqua">

    <TextBox Width="100" Mar

ScrollViewer.ActualWidth being screwy


So I am working on something where I want to detect and auto scroll a scrollviewer.  It should be really straight forward, and I have some code that was similar and works perfectly.  It is frustrating me to no end though because in the working code example ScrollViewer.ActualWidth is providing me with what appears to be the width of the visible area.  In the case where the code is not working, the actual width is always the same as desired width and content width and extent width.

<ScrollViewer HorizontalAlignment="Stretch"




How To Judge a Control in ScrollViewer Viewerport



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"
    Title="MainWindow" Height="300" Width="300"
    <ListBox x:Name="HelloKitty">
          <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
using System.Windows;
using System.Windows.Media;

namespace LotsOf
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class M

Popup with ScrollViewer and VerticalScrollBarVisibility=Auto not displaying correctly in 3.5sp1


If I have a Popup which contains a ScrollViewer and I set VerticalScrollBarVisibility=Auto, if the scroll bar is required the Popup is not sized correctly. This looks like it was fixed in 4.0  ( at least my test case works in 2010 and not 2008 ) but I'm hoping there's a workaround for 2008 since I can't move to 2010 yet. Here's some example XAML which shows the issue


Weight scales


I'm new to hardware interfacing and I'm developing an application that sends a command to a scale and retrieves the weight data from the scale and prints it in a textbox. The problem is how I can return the data from the scale : -


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend