WPF scrollviewer on dock panel does not scroll mousescroll - c#

I have an application that works with different tabs. At left side I have my menu and at the middle I have DockPanel. According to menu selection I am adding a windowbase window as child to my dock panel and with mouse ball scroll but it does not scroll. Normally when you are over scrollviewer area it automatically triggers scrolling but for dock panel its just moving when I am over scroll bar not on whole dock panel.

Thanks guys I was thinking that when I add scrollviewer into the DockPanel and clear children than the scrollvier also be removed. But it is not like that.At the beggining I was using it like following code
<ScrollViewer x:Name="innerScrool" VerticalScrollBarVisibility="Auto" VerticalAlignment="Top" MinHeight="350"><DockPanel Margin="0,10,0,0" VerticalAlignment="Top" x:Name="ControlPanelContent">
But I change the code take the scrollviewr inside and the problem solved.

Related

Why won't my ScrollViewer Scrollbars appear on the screen?

I have an issue with a WPF C# project, where I have a StackPanel on my Form, within that I have a DockPanel which has items added to it programmatically, the problem is that the items are going out of the form's bounds and I would like to scroll through these, I already have a method for "Scrollifying" the items, but for the life of me I can't see why the scrollbars aren't appearing on the screen, am I missing something?
Code is below, any suggestions are more than welcome.
private void ScrollifyStackpanel(StackPanel Panel)
{
ScrollViewer SV = new ScrollViewer();
SV.Height = Panel.ActualHeight;
SV.Width = Panel.ActualWidth;
SV.CanContentScroll = true;
SV.Content = Panel;
}
Xaml
this is the stackpanel containing the (should be) scrollable content
<StackPanel Name="divParentPanel" VerticalAlignment="Top" DockPanel.Dock="Left" Margin="10" Width="Auto" HorizontalAlignment="Stretch" CanVerticallyScroll="True">
Specify ScrollBar Visibility:
ScrollViewer SV = new ScrollViewer();
SV.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
SV.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
Sometimes it can happen that ScrollViewer can't detect the necessity of ScrollBars at exact moment of size change. It's totally
context specific but set the visibility to Visible to be safe always.
#Reece Try by setting the height for stack panel. since StackPanel cannot have dynamic height. Or else you can use Grid instead of StackPanel

WPF Facebook like scrollbar behavior using scrollviewer

I have a simple scrollviewer setup in my wpf application. Everything works fine, Now I want my scrollviewer's content should use the space of my the scollbar as well, As my scrollbar is transparent it could easily display the content.
Just like the scrollbars in facebook. Attached is the image of the output. Green Section is the content and red section is scollviewer's area.
I am using WrapPanel in my scrollviewer, this is the code snippet
<ScrollViewer x:Name="ScrollViewer1"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Hidden">
<WrapPanel x:Name="WrapPanel1" SizeChanged="WrapPanel1_SizeChanged" />
</ScrollViewer>
You have to edit the ScrollViewer's ControlTemplate which should look like the one in this page : http://msdn.microsoft.com/en-us/library/aa970847(v=vs.110).aspx
In the ScrollViewer Control Template Example, you can see that the ScrollContentPresenter is inside a Border which is inside the first row of a 2-rows Grid.
Setting the RowSpan to 2 for this Border would achieve the effect you want.

StackPanel is not scrolling

I want to put lots of controls inside a StackPanel and user can scroll up and down. I have a simple StackPanel inside a grid.
<Grid>
<StackPanel>
</StackPanel>
</Grid>
If I'm not wrong, I've seen that StackPanel scrolls, but now it is not working. Does it support scrolling or it is not supported at all? ( I prefer not to put it inside a ScrollViewer). thanks
Nothing really scrolls unless it has a ScrollViewer inside. When you do it like you're doing it now, you'll see only the items that fit on the screen, and others will be 'out of screen borders'.
So I'm afraid you'll have to add a ScrollViewer. It's actually a good thing that StackPanel doesn't scroll by default.

Expand borders on xaml app?

My xaml application is not filling up my screen when I debug it.
As you can see my buttons are displayed at the bottom.
After debugging the app the buttons are now half way up.
This is the positions that xaml has set as default, both are at auto auto.
Instead of using Auto, use Bottom for both.
If your buttons are in a stack panel, you can lock (anchor) the stack panel to the bottom of your LayoutRoot and set the height of the stack panel to a height close to the height of your buttons. Then, I would look at setting the LayoutRoot width and height to auto.
You can also configure your grid with rows and cols along with their dimensions.
try this xaml:
<Grid>
<StackPanel HorizontalAlignment="Center" Margin="0,278,0,0" Width="517" Orientation="Horizontal" Height="50" VerticalAlignment="Bottom">
<Button Content="Button"/>
<Button Content="Button"/>
</StackPanel>
</Grid>
On your grid you'll see little locks positioned at the center of ever side of the grid.
If you add an object and move your mouse along the locks your cursor changes to a hand pointing a finger icon. If you click on the lock at that point, you'll see the lock either locks or unlocks. (i.e. you'll see a larger gap between the lock lines). It helps maintain the anchor position of the object when resizing the screen.
This is a screenshot with the stack panel selected. Notice that only the bottom anchor is locked.

dockpanel alternatives

I have read that I can't have my dockpanel scroll so im looking for alternatives
I want to have a lot of slider controls(unknown number) left to right in a panel of some sort that can scroll so I can view all the sliders. I tried with dock panel but of course that didn't work. What can I do to make the dockpanel work or what do I replace dockpanel with(the replacement would need to support children)?
Thanks!
EDIT:
http://i.stack.imgur.com/J5a4u.png
here is the idea but it needs to scroll horizontally
David Brunelle Does work but its not quite what I want. Id like the scroll bar to be on the top of the control and not attached to the bottom of the window.
I'm not sure I understand, but you can use a panel within a ScrollViewer
Something like this :
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Margin="2,2,2,2">
...
</StackPanel>
</ScrollViewer>
This will allow for vertical scrolling. You could do the same for horizontal scrolling. I do not know if this would work with a docking panel, but I know it does with a stack panel.
Hope that helps.
I would use a ListBox as it will handle the scrolling part for you, then you can set the ItemTemplate (if you want) and you can use data binding (using an ObservableCollection or a DataView

Categories