Change number of lines mouse wheel scrolls in WPF ListBox - wpf

In a WPF listbox, rotating mouse wheel will scroll list by the number of lines specified in Windows Control Panel, in Mouse Wheel options.
How can I change this, for example I want to scroll WPF ListBox, one line anytime, using mouse wheel.
Thank you.

As you stated it is a control panel setting and you are trying to override it. That will confuse the user. I recommend you to not do that.
However you could try and override various events and position the vertical scrolling by using scrollViewer.ScrollToVerticalOffset(...);

As stated by ygoe in a comment, what you are looking for is :
ScrollViewer.CanContentScroll="False"
In my tests, it does scroll the list one line at a time.
Of course, you should consider that it overrides a global windows setting, as stated by Erno

Related

Adjusting TextBox contents with ScrollBar WPF

I am working out of the 3.5 .Net Framework. I have a textbox next to a scroll bar in a stackpanel. I would like it to be that when the user clicks the "up" arrow of the scrollbar, the contents of the textbox are incremented, and decremented when the click the "down" arrow of the scrollbar. The problem is I am not sure which event I need to fire to do this. I've tried MouseDown, MouseUp, PreviewMouseDown (which fires but I don't know how to differentiate whether the up or down arrow was clicked), PreviewMouseUp (same problem), StylusUp, StylusDown, PreviewStylusDown, PreviewStylusUp, StylusButtonDown, StylusButtonUp, and the previews for that also. As I am debugging, I am using messageboxes to let me know I've entered that event, but none have shown (expcept for the PreviewMouseDown). Being fairly new to WPF, I am basically baffled.
Does anyone know which event I should be looking for? Thanks.
You should not abuse the ScrollBar for this but create a new control with two buttons.

WPF Popup Alternative

I have a window with a popup that pops when an item in a listview is double clicked.
It centers to the main window and looks really nice floating there.
The problem is when the user moves the main window or selects another program, and the popup floats on top of other stuff.
I would like to have something like a popup, meaning that it floats on top of other elements in the window, but sticks with the main window when it moves (stays centered), and doesn't float on top of other programs.
Can I make a popup act like this, or is there a better way to do it?
Popups will not move while the window is resized or moved. Because, Popups/Context menus are not the part of Visual Tree. You have to use Adorner for this. I will suggest to read this four part series for a quick start on Adorner.
It's possible that an Adorner will fit your needs in this case better than a popup. Adorners can float above your window, too. There are a few differences, mainly that an adorner is bound to a UIElement (which include windows).
If you are willing to use a third-party/open source (MS-PL) option, the Extended WPF Toolkit has a ChildWindow control.
It's technically not a separate window, but it appears to be a separate window to the user.
I have not found a way to make Popups stop doing that in WPF
As an alternative, you can create a UserControl which acts like a Popup.
Usually I host the content section of the app along with the Popup within a Canvas control, and when IsPopupOpen gets changed to True I set the popup Visibility = Visible.

How can I set the focus for a DevExpress XtraGrid so the mouse wheel works right away?

The UI for my WinForms app is centered around a DevExpress XtraGrid.
Usually, the first thing a user wants to do is scroll the grid, so the normal instinct is to move the mouse wheel.
But currently, you have to click a row in the grid first, which is annoying.
I tried to use BaseView.Focus method, but this did not work - still had to click a row before the wheel would work.
Any suggestions on how to accomplish this?
By default, the Grid is scrolled by mouse wheel only if the mouse pointer is above the grid. So, an attempt to focus it does not help. To change this behavior, you should change the static SmartMouseWheelProcessing property in the form's constructor as shown below:
DevExpress.XtraEditors.Drawing.MouseWheelHelper.SmartMouseWheelProcessing = false;

DataGrid vertical scrollbar problems after resizing

I'm working with a DataGrid in Silverlight.
If I have enough items so that the vertical scroll bar is visible for all sizes of the window, and I re-size the window a few times, the vertical scroll gets out of sync. The thumb gets to small as if the control thinks that there are more items then it is. When I drag the thumb towards the bottom or the top, the content starts to jump. It happens all the time, very frustrating. The DataGridis laying within a DockPanel that is re-sized according how large the window is (no specific size that is)
Anyone have any ideas?
I have some similar issues. Most of them could be resolved by calling UpdateLayout on the datagrid.
I too have a datagrid in a dockpanel. When I scroll down and select the bottom record and then reload my datagrid the horizontal scrollbar seems to cover the last record. And the vertical scrollbar appears to be as far down as possible and cannot be dragged down further.
If i use the scrollwheel on the mouse the last record can be brought into view.
This only occurs when i show my application in a maximized window.
Have you gotten anywhere with this?
I tried similar approach with the derived DataGrid.
The difference is that the OnApplyTemplate would only get the instance of VerticalScrollbar and the separate public method was introduced to invoke the UpdateLayout() on the scroll bar. Such method is to be called explicitly in the situations that may bring the scroll bar size out of sync (DataGridcontent resizing, etc.)
Sometimes the UpdateLayout() alone was not enough so I added flipping the scroll bar visibility - that worked better though still not in 100% of situations
This is a bug in the datagrid. You can solve this by inheriting from the datagrid and on the OnApplyTemplate method you search for the scrollbars and manually update their layout:
public override void OnApplyTemplate()
{
verticalScrollBar = this.GetTemplateChild("VerticalScrollbar") as ScrollBar;
if (verticalScrollBar != null)
{
verticalScrollBar.UpdateLayout();
}
}
If this still doesn't work then try calling the OnApplyTemplate method manuallty in code.
In data grid Style remove the vertical scroll bar and follow the Below Steps
Step1: Sorround the DataGridRowsPresenter with Scroll Viewer
Step2: Make HorizantalScrollBarVisibility to Disable
Step3: VerticalScrollBarVisibility to Auto

WinForm Panel scrolling without a scrollbar?

I'm creating a User Control that's basically a Panel (with random content inside), and I need to be able to scroll up and down this Panel using buttons (up and down) rather than the scrollbar.
The reason I have to do it this way is because the program will be used on a touch screen monitor and we need big buttons rather than an ugly little scrollbar.
I've been messing around with the VerticalScrollbar properties, and none of them seem to do anything. I've noticed that if I set AutoScroll to false, AutoScrollPosition actually shows coordinates, except negative of what it should be. Also, I've noticed that panel.VerticalScrollbar.Visible = true; only seems to work when placed outside of the constructor. Is there a reason for that?
Basically, WinForms' scrollbars are very confusing (buggy?) to me. Does anyone know a good way to scroll up and down a panel programmatically with buttons (I don't care if I need to have an invisible scrollbar).
Thank you! =D
Make your UserControl a regular UserControl (i.e inherit from UserControl instead of Panel) and place a Panel on your UserControl. Put any content/controls on the inner Panel, and then change the Panel's Left and Top properties to move it around without scrollbars. You could also add buttons to your UserControl to handle the movement of the inner Panel.
A simpler way, however, might be to just use really wide/high scrollbars, and set their Thumbwidth (I think this is the property) to the same large value - this will produce scrollbars that are easy to use with the fingers. To my knowledge there's no way to do this with the scrollbars that appear on a Panel with Autoscroll set to True, so you'd still need to use the method I mentioned above (with an inner Panel sitting on your UserControl) and add the scrollbars to move it yourself.
I agree that scrollbars in Windows suck, so while I'm normally in favor of just using the standard controls that everyone is used to, I don't see anything wrong with rolling your own in this case.

Resources