Silverlight / WPF - Scroll Bar in Xaml form...

Asked By sushant kumar kesari
10-Sep-11 01:46 AM
hello friend

i am working in wpf project. i have i big form how to set scroll bar in .xaml form .
in property there is no option for auto scroll. 
please reply asap ....

thanks
  Devil Scorpio replied to sushant kumar kesari
10-Sep-11 02:47 AM
Hi Sushant,

This article may be helpful

The ScrollBar tag in XAML represents a WPF ScrollBar control.

<ScrollBar></ScrollBar>


The Width and Height properties represent the width and the height of a ScrollBar.  The Name property represents the name of the control, which is a unique identifier of a control. The Margin property tells the location of a ScrollBar on the parent control.

The Orientation property sets the direction of scrolling that can be either horizontal or vertical.

The following code snippet sets the name, height, width, orientation, margin, and background of a ScrollBar control.   
<ScrollBar Name="McScroller" Orientation="Horizontal"
       Width ="250" Height="30"
      
Margin="10,10,0,0"
       Background="LightSalmon" />


The ScrollBar looks like Figure 1.

SBarImg1.gif
Figure 1.


Setting up ScrollBar Value

The Value property of ScrollBar sets up the current value of a ScrollBar control. The Minimum and Maximum properties represent minimum and maximum range of a ScrollBar. In the following code, I set the Value property to 50 and now ScrollBar looks like Figure 2.

<ScrollBar Name="McScroller" Orientation="Horizontal"
       Margin="10,10,0,0"
       Width ="250" Height="30"
       Background="LightSalmon"
       Minimum="1" Maximum="240"
       Value="50" />

SBarImg2.gif
Figure 2.


Creating a ScrollBar Dynamically

The ScrollBar class in WPF represents a ScrollBar control. This class is defined in using System.Windows.Controls.Primitives namespace. Before you use this class, make sure to import this namespace.

The following code snippet creates a ScrollBar at run-time and sets its orientation, width, height, background, minimum, maximum and value properties.

private void CreateDynamicScrollBar()
{
    ScrollBar hSBar = new ScrollBar();
    hSBar.Orientation = Orientation.Horizontal;
    hSBar.HorizontalAlignment = HorizontalAlignment.Left;
    hSBar.Width = 250;
    hSBar.Height = 30;
    hSBar.Background = new SolidColorBrush(Colors.LightSalmon);
    hSBar.Minimum=1;
    hSBar.Maximum=240;
    hSBar.Value=50;
    LayoutRoot.Children.Add(hSBar);
}


How to add scroll event handler to a WPF ScrollBar

The following XAML code snippet adds Scroll event handler to a ScrollBar.

<ScrollBar Name="McScroller" Orientation="Horizontal"
       Margin="10,10,0,0"
       Width ="250" Height="30"
       Background="LightSalmon"
       Minimum="1" Maximum="240"
       Value="50" Scroll="ScrollBar_Scroll"/>

The Scroll event handler code looks like following:

private void ScrollBar_Scroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
{
    // Do something here
}


Reference :- http://www.longhorncorner.com/UploadFile/dbeniwal321/230/
  sushant kumar kesari replied to Devil Scorpio
10-Sep-11 03:48 AM
thanks

 but my problem is not solve....

i have a big form. it is not fit to screen. how to use scroll bar to scroll to the window.
my form size is more than 1000. 
  Riley K replied to sushant kumar kesari
11-Sep-11 12:43 AM

Put a ScrollViewer inside your Window:

<Window x:Class="WpfApplication2.Window1"
  Title="Window1" Height="300" Width="300">
 
  <ScrollViewer >
    <!-- Window content here -->
  </ScrollViewer>
</Window>

This should solver your problem

Cheers

Create New Account
help
Disable scroll bar in MVVM shell page Silverlight / WPF hi. . i am showing my page in inside shell page using mvvm pattern. now i have a scroll bar in the page and also i have browser scroll bar. here when i disabled my xaml page scroll bar i cant see bottom page information and i try use my browser scroll bar in order to see the bottom xaml page info. i cant able to see. so i want to shell page info with out using my xaml scroll bar. i want see this using my browser scroll bar only how to achieve this
Unable to import namespace System.Data Silverlight / WPF Hello, I m using Silverlight Application in which I have a class file, which doesn't allow to import System following error. "You can't add reference to System.Data as it was built against Silverlight runtime. Silverlight projects will only work with Silverlight Assemblies." Can u please help me. . Thank u in advance. HI Sheetal, No you cannot do that in Silverlight. . . You have to use WCF RIA Services if you want to do some serious data work with Silverlight. Check to see that System.Data is included in the references for that particular project
Blend2 - August CTP - Silverlight 1.1 .NET Framework Hi, I downloaded this CTP to Visual Studio 2008 Beta2 VHD after downloading silver light from these links: 1) http: / / www.microsoft.com / silverlight / downloads.aspx - Silverligth 1.1 2) http: / / www.microsoft.com / downloads / details.aspx?FamilyId = B52AEB39 en When I fired up this Expression, it only showed me following project types: 1) WPF Application (.exe) 2) WPF Control Library 3) Silverlight Application (JavaScript) I am assuming that the last project type is for Silverlight 1.0 and is not for Silverlight 1.1. I was hoping to see Silverlight 1.1 Client Application' project type. Am I missing something? Or is the last project
Guidelines .NET Framework Up until now I have been programming in WPF and auto-sizing mostly every control (grids, buttons, comboboxes, etc.). This has brought up an could shift position. I was wondering, is their any guidelines for official UI Design in WPF? Something to say when to auto-size and when not to? That sort of thing User Experience Guidelines, but when talking about sizing controls it doesn't seem to mention WPF's wonderful auto-sizing abilities at all. So what guideline am I to follow then Or am I just left to wing it? Expression Interactive Designer Discussions Windows Vista (1) Silverlight (1) WPF (1) Wnforms (1) Brennon (1) Chad (1) Characteristics (1) D11D9E6B0682 (1) Howdy, I think you have found the only official WPF guideline document. Taking that you have probably agreed a coding standard / naming convention within your com http: / / www.x-coders.com I'm really #00FF00 and have no experience with WPF / Silverlight - -yet- - so I have a comment and a question. / / comment WPF offers creative designers the
WPF Printing and Print Preview This article shows some ways on how to print and preview documents using WPF. Introduction I was searching on how to print using WPF for my application. The requirement is that there’s already a background image where text So while searching, I found out that there are several ways to print documents using WPF. Let’s start with the easy ones. Printing a Visual A Visual is an object that provides rendering support in WPF. Basically, these are the objects that we usually see in a WPF application, like user interface controls, images, ellipses, etc. Below is the screenshot of a simple are two ways to get a DocumentPaginator object. · A DocumentPaginator can be obtained from a WPF document. A document is divided into two categories: FlowDocument and FixedDocument. A FlowDocument is a FlowDocument x : Name = "flowDocument" IsOptimalParagraphEnabled = "true" IsHyphenationEnabled = "true" IsColumnWidthFlexible = "false" ColumnWidth = "Auto" PagePadding = "Auto" > < Paragraph > WPF Printing < / Paragraph > <!- - REMOVED OTHER PARAGRAPHS FOR READABILITY - -> < / FlowDocument > < / FlowDocumentReader > < / Grid > < / Window > The following code listing