How can i make a control sticky? - silverlight

How can i make a control to be sticky? I have a scrollviewer and inside that a grid. Inside grid i have a button. The button is set to horizontal alignment - center and vertical alignment - bottom. Now, when the size of the grid increases the button is no more visible on the screen. I have to scroll to really see the button. Can i make the button to be sticky so that it is always there at the bottom of the screen?
Thanks in advance :)

Anything you put inside the scollviewer will be part of the scrollable content. You can either remove that control and put it outside the scrollviewer, or put inside a floating popup control.

Remove the button from inside the ScrollViewer:
<Grid>
<ScrollViewer>
//Content
</ScrollViewer>
<Button HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Grid>

Related

Adding a vertical scroll bar to a wpf Grid while keeping the header line fixed

I am trying to add a vertical scrollbar to a in WPF. I tried adding the grid into a component which works but then the whole grid scrolls and the header row scrolls as well. I tried without the but then didn't find a VerticalScroll property for the control.
Any help would be very appreciated,
Thanks
Pat
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled">
//Put the content that you want scrollable here
<Grid>
</Grid>
</ScrollViewer>
Not enough information really maybe post your code?

Scrollviewer & Canvas

I am trying to load an image within a canvas such that, if the size of image overflows the canvas, the scroll bars should get activated (MS Paint style)
<Window>
<ScrollViewer>
<Canvas ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<Image Source="SampleImage.jpg" />
</Canvas>
</ScrollViewer>
</Window>
Now as Canvas is stretched to Window's size, scroll-bars won't appear as Canvas is not actually overflowing out of the Window.
Secondly, as the Image is much bigger than the Canvas, it is getting clipped at the bounds of Canvas, so ScrollViewer doesn't think that its content: Canvas is actually overflowing.
It happens a lot of time with StackPanels too, that even though the bound data has tens of rows, but still the scrollbars don't get activated. Sometimes scrollviewers appear as mystery to me.
So, what should be the basic logic kept in mind when using ScrollViewer control.
Thank you.
Edit: Just edited the question title, so that whosoever has problem with canvas can get this question easily in search.
From MSDN:
Canvas is the only panel element that has no inherent layout characteristics. A Canvas has default Height and Width properties of zero, unless it is the child of an element that automatically sizes its child elements. Child elements of a Canvas are never resized, they are just positioned at their designated coordinates. This provides flexibility for situations in which inherent sizing constraints or alignment are not needed or wanted. For cases in which you want child content to be automatically resized and aligned, it is usually best to use a Grid element.
Hovever, you can set Canvas Height and Width explicitely:
<ScrollViewer Height="100" Width="200">
<Canvas Height="400" Width="400">
//Content here
</Canvas>
</ScrollViewer>
Maybe one of these two Links might help you:
Silverlight Canvas on Scrollviewer not triggering
ScrollBars are not visible after changing positions of controls inside a Canvas

XAML - Enable scrollviewer in tab item

I added a scroll bar in a tab item, but the scroll bar is not enabled.... I can't figure out what I have done wrong... Can someone point me in the right direction? CanContentScroll is set to true....
without code to see what you are attempting it's hard to know where you are going wrong...
However, should look something like:
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" >
<!-- content here -->
</ScrollViewer>
the scroll bars should become visible automatically, if the content increases beyond the size of the control the scrollviewer is placed within.

Horizontal Scrolling buttons in WPF [duplicate]

This question already has answers here:
Custom listbox with move fwd/bwd buttons
(3 answers)
Closed 3 years ago.
I have a horizontal stack panel that contains buttons.
I need to be able to scroll this either right or left to make the buttons rotate through the stack panel because there are more buttons than there is room on the screen.
Using a horizontal scroll bar is not an option because it ruins the look of the application and does not rotate all the way around in a circular fashion.
How can I either change the scroll bar to just have a right arrow on the right hand side and a left arrow on the left hand side to handle the scrolling and not completely rotate all the buttons. ie, works like a normal scroll bar but looks way better.
eg. << [Btn][Btn][Btn] >>
Or have a way or rotating the buttons in a circular fashion so the is no real start or end the the horizontal collection of buttons and some way for a user to move the position of the buttons they can see.
The container control does not to have to be a stack panel, that was just the best container for the buttons initially.
Xmal and styling would be my first choice, but there is no issue using code behind either.
Making your own custom scroll buttons is a issue?
If not, you can create a ItemsControl, in the style set the ItemsPanel to
<ItemsPanelTemplate x:Key="ItemsPanelStyle">
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
and in the ControlTemplate of the ItemsControl
<ScrollViewer
x:Name="PART_ScrollViewer"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden"
CanContentScroll="True"
>
<ItemsPresenter/>
</ScrollViewer>
your toolbar buttons will be the actual ItemsSource of this ItemsControl. If you create now a button in the template (scroll right, the scroll button you need), and on it's command you execute
ScrollViewer myViewer = GetTemplatedPart("PART_ScrollViewer");
if(myViewer != null)
{
myViewer.LineRight();
}
this should scroll each element to the right untill the end of your list of buttons (notice advantage: no matter what the width of the element is).
The same thing you can do to the left.
HTH, daniell

WPF window scrolling with top menu

I'm running into a dilemma. When I make the ScrollViewer the main content object of my window, scrolling behaves exactly like I want it to. You resize to make it smaller than the content and the window and scroll bars appear. The problem comes in when I want the to menu to be static and the rest of content to be scrollable. I want the scroll bars to behave the same way as a browser window does, meaning when you resize it, the scroll bars appear based on the size of the content. When you expand the window, the content takes up the entire real estate of the window. Is that possible in WPF?
Help would be GREATLY appreciated.
Make a DockPanel the main content object of your window. Insert your top menu as the first child (with DockPanel.Dock="Top") and the ScrollViewer (containing the rest of the window's content) as the second child. In a DockPanel, the last child takes up all the remaining space, which should be what you want.
<Window ...>
<DockPanel>
<MyMenu DockPanel.Dock="Top" ... />
<ScrollViewer>
....
</ScrollViewer>
</DockPanel>
</Window>

Resources