Enable WPF DataGrid Panning? - wpf

I have a WPF DataGrid that I allow to expand vertically as far as needed, and so there is no need to scroll or pan the content within the DataGrid itself. However, it's inside of a Window that has a ScrollViewer.
When I run it, the DataGrid grows vertically to allow all rows as expected, and the ScrollBar along the edge of the Window appears as expected. But I can only touch/pan up and down if I do it on the areas of the Window that lie outside of the DataGrid itself. The DataGrid accepts and effectively blocks the input (which is not unexpected.)
So how can I make the DataGrid "pass" this touch/pan input upward to it's container, i.e. the Window, so that the Window will know it needs to scroll?

I might be wrong here, but I thought the visual tree in WPF bubbles upwards. This would mean that your DataGrid, as I am interpreting it right now, would capture the event and handle it correctly as you mentioned.
But once that's done, it bubbles up to its parent (the window) thus not passing the event to your scrollviewer. It does this because the datagrid in scrollviewer are probably siblings instead of having a parent/child relationship.
One option would be to setup a command to handle this behaviour.
Or you could use the dispatcher:
this.Dispatcher.Invoke( () =>
control.ScrollToVerticalOffset(scrollViewerChannelBtns.VerticalOffset + 50);

In xaml
ScrollViewer.PanningMode="Both"

Related

Why Popup part of combobox is resizable in one context and not in the other?

I have a wpf cusotm control derived from combobox System.Windows.Controls.ComboBox the control template is redefined and the popup (PART_Popup) contains a DataGrid and some other control. I use it in two places - in TabControl(,Grid) and in a Window(Grid,,Grid). When the DataGrid is resized either by dragging columns or from code the behavior is different: in window the Popup resizes in TabControl Popup remains the same and a scrollbar appears if necessary.
I need to know what can cause such difference.
Edit
Datagrid is has HorizontalAlignment="Stretch"
I find it. By mistake there was
Popup.Width=Me.Width
instead of
Popup.Width=Me.ActualWidth
This caused resizability in case when the Me.Width was not set.

WPF Adorner Overlay Problem

I am trying to achieve functionality similar to that of a Popup, without using a Popup, but instead adorning my ContentControl with a basic adorner. Basically, I want the ContentControl to have an "overlay" effect, whereby it is the topmost object, above all other elements - similiar to that of the Popup control.
Here is the problem that I am running into, and I am hoping that someone can point out where I am going wrong:
I have a stand grid with two row definitions. The first row contains a UI element - for example, a rectangle. The second row contains a custom control that I have developed to emulate the functionality of a "drawer" sliding out. Basically, when I click on button, I am going to animate a TranslateTransform to "slide" my ContentControl "up". This works fine - except that it gets cropped underneath the rectange in the first row of the grid. If I remove the row definitions in the grid, then when the desired behavior is achieved - the ContentControl is moved "up" and partially "on top" of the rectangle. The rectangle is merely a place holder for what I am trying to achieve. I basically want to have a drawer type control that can slide out and be on top of all other controls.
I am somewhat new to using the Adorner class, so, I am hoping that someone can please point out where I am going wrong.
Thanks.
Chris
Change the parent of the adorner to the full grid, and not just your control. If you put a control in a grid row, and set the adorner to adorn the control, it will usually be clipped to that row because the control is.

Silverlight toolkit Expander doesn't expand when the size of its content changes

I have a silverlight expander control which wraps a grid. In the grid, I have a number of text boxes, combo boxes as well as some invisable (collapsed) text blocks. I also have an animation and when it is triggered the grid shows those hidden text blocks.
My problem is, when the hidden text blocks are shown after the animation is run, these text blocks push other controls down and because the expander doesn't resize itself, the controls at the bottom get pushed outside of the expander and become invisible.
I tried to call UpdateLayout() after the SizeChanged event of the grid but doesn't work.
Any suggestions on how to resolve this issue would be much appreciated!!
I actually have fixed this problem by myself. I discovered in the style of the expander control, a while ago I put an ExpandableContentControl instead of normal ContentControl because it has a nice animation when you expand/collpase it. But this control doesn't resize properly... (see http://silverlight.codeplex.com/workitem/4544?ProjectName=silverlight) I guess this is why the AccordionItem control is so buggy because it also has an ExpandableContentControl in it. As soon as I replaced the ExpandableContentControl with a normal ContentControl, the expander worked as expected. :)
The problems is because the expander always use the same width (or height), so you must recalculate the width of the grid by code and assign it to the columndefinition.

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

Binding a Popup to another control's relative screen position

I'm writing an XBAP with a complex Popup (Canvas Z-index of 99 with a grid on it...) that I would like to "attach" to the button that opens it and follow that button around wherever it goes on the screen. For example, if the button is in a ListBox or an XamDataGrid I would like the popup to follow the button as it scrolls through. If it is beneath an Expander I want it to stay attached to the button when the expander forces it to move, etc.
Any Ideas?
When using a Popup, neither PlacementTarget nor CustomPopupPlacementCallback is used after the popup has originally appeared. So any use of these properties will not allow the popup to track the button as it moves.
Several ways occur to me of achieving what you desire:
Attach a custom Adorner to the button and put the popup inside it. Disadvantage: Popup is not connected to Button or surrounding elements, so it won't inherit properties & DataContext from them.
Attach a custom Adorner to the button. This adorner will get measure and arrange calls when the button moves relative to the AdornerLayer, allowing you to manually update the Popup position. As long as your AdornerDecorator doesn't move relative to your Window (eg if it is the direct child of the Window), you can easily detect the AdornerLayer being moved by monitoring changes to Window size. Disadvantage: Complex to code & get right.
Don't use a Popup at all. Instead wrap the button in a <Grid> alongside a <Canvas> with zero width and height and the desired position. Inside the <Canvas> add the UserControl for the popup with an appropriate ZIndex. It will extend past the edge f the Canvas, which is just fine in WPF. Instead of using a Popup control just control the visibility of the UserControl. Disadvantage: Will not really be totally on top of all other objects, can't extend off edge of window (may not be an issue for XBAP, though).
I'm not sure if it will auto-update for you or not, but the PlacementTarget property allows you to specify a control to position the popup relative to. If that doesn't work, then maybe CustomPopupPlacementCallback will do the trick?

Resources