locked
ScrollViewer in NavigationWindow RRS feed

  • Question

  • Hello,
     
    Is it possible to place a scrollviewer into a NavigationWindow so that the vertical overflow of a page's content can be seen?  I am using NavigationWindow and PageFunction.

    Thanks!!

    Daniel
    -DK
    Friday, October 10, 2008 8:47 PM

Answers

  •  

    Hi,


    It's possible.
     

    In order to use ScrollViewer in NavigationWindow , we can first create a style for NavigationWindow, and visualize its template property with a ScrollViewer, Then you can see the ScrollViewer when use.

     

    Some code in App.xaml:

    <Application.Resources>

            <Style x:Key="{x:Type NavigationWindow}" TargetType="NavigationWindow">

                <Setter Property="Template">

                    <Setter.Value>

                        <ControlTemplate TargetType="NavigationWindow">

                            <ScrollViewer Background="White"   HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">

                                <AdornerDecorator>

                                    <ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/>

                                </AdornerDecorator>

                            </ScrollViewer>

                        </ControlTemplate>

                    </Setter.Value>

                </Setter>

            </Style>

        </Application.Resources>

     

    Thanks.


    Jim Zhou -MSFT
    • Marked as answer by Jim Zhou - MSFT Wednesday, October 15, 2008 11:31 AM
    • Marked as answer by Jim Zhou - MSFT Wednesday, October 15, 2008 11:31 AM
    • Unmarked as answer by dotBomb Wednesday, October 15, 2008 9:37 PM
    • Marked as answer by Jim Zhou - MSFT Thursday, October 16, 2008 2:45 AM
    Tuesday, October 14, 2008 7:09 AM
  •  

    Hi,

     

    NavigationWindow is mainly used to natigate pages from one to another,As far as I know, we often need't to set the Content property of the NavigationWindow, we are more care about its Source property, as a NavigationWindow, we ofter don't set its partial  Class in the code behind.

     

    --> That is, no scrollbar appears. 

     

    You have set the HorizontalScrollBarVisibility and   VerticalScrollBarVisibility property of ScrollViewer to “Auto”, Auto means when the Content is not bigger than their container,   the scrollbar will not appear, if you want to see it whenever, you can simply set the HorizontalScrollBarVisibility and VerticalScrollBarVisibility property to “Visible”.

     

    //you can see the ScrollBar in this case
    <
    NavigationWindow 

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Source="Page1.xaml"

    Title="Window1" Height="300" Width="300">

    <!--other code-->

    <ScrollViewer Background="White" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">  

    <!--other code-->

     

     

    Page1.xaml:

      <Grid>

            <TextBlock >

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

            </TextBlock>

        </Grid>

     

    In this case, the TextBlock's content can not be contained in the Window by one common row, then you will see the ScrollBar.

    -->Also, this messagebox never appears:

    Because you haven't set any event fired to show this MessageBox.

     

     


    Thanks


    Jim Zhou -MSFT
    Thursday, October 16, 2008 2:44 AM

All replies

  •  

    Hi,


    It's possible.
     

    In order to use ScrollViewer in NavigationWindow , we can first create a style for NavigationWindow, and visualize its template property with a ScrollViewer, Then you can see the ScrollViewer when use.

     

    Some code in App.xaml:

    <Application.Resources>

            <Style x:Key="{x:Type NavigationWindow}" TargetType="NavigationWindow">

                <Setter Property="Template">

                    <Setter.Value>

                        <ControlTemplate TargetType="NavigationWindow">

                            <ScrollViewer Background="White"   HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">

                                <AdornerDecorator>

                                    <ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/>

                                </AdornerDecorator>

                            </ScrollViewer>

                        </ControlTemplate>

                    </Setter.Value>

                </Setter>

            </Style>

        </Application.Resources>

     

    Thanks.


    Jim Zhou -MSFT
    • Marked as answer by Jim Zhou - MSFT Wednesday, October 15, 2008 11:31 AM
    • Marked as answer by Jim Zhou - MSFT Wednesday, October 15, 2008 11:31 AM
    • Unmarked as answer by dotBomb Wednesday, October 15, 2008 9:37 PM
    • Marked as answer by Jim Zhou - MSFT Thursday, October 16, 2008 2:45 AM
    Tuesday, October 14, 2008 7:09 AM
  • Jim,

    Thanks so much!  Your recommendation was very helpful!

    Dan
    -DK
    Wednesday, October 15, 2008 3:26 PM
  • Jim,

    Would you happen to know why this XAML has no effect on the NavigationWindow?  That is, no scrollbar appears.  Also, this messagebox never appears:

    if (this.HandlesScrolling) { System.Windows.MessageBox.Show("This window handles scrolling", "NavigationWindow Message"); }

    Is this a deficiency of the NavigationWindow class?

    <NavigationWindow  
     
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="WizardSample.NavigationWindow" 
    Title="Wizard Dialog Box" ResizeMode="CanResizeWithGrip" SizeToContent="Width" WindowState="Maximized">  
     
    <NavigationWindow.Resources> 
     
    <Style x:Key="{x:Type NavigationWindow}" TargetType="NavigationWindow">  
     
    <Setter Property="Template">  
     
    <Setter.Value> 
     
    <ControlTemplate TargetType="NavigationWindow">  
     
    <ScrollViewer Background="White" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">  
     
    <AdornerDecorator> 
     
    <ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/>  
     
    </AdornerDecorator> 
     
    </ScrollViewer> 
     
    </ControlTemplate> 
     
    </Setter.Value> 
     
    </Setter> 
     
    </Style> 
     
    </NavigationWindow.Resources> 
     
    </NavigationWindow> 
     

    Thank you,

    Dan
    -DK
    • Edited by dotBomb Wednesday, October 15, 2008 9:43 PM
    • Marked as answer by Jim Zhou - MSFT Thursday, October 16, 2008 2:45 AM
    • Unmarked as answer by Jim Zhou - MSFT Thursday, October 16, 2008 2:45 AM
    Wednesday, October 15, 2008 9:38 PM
  •  

    Hi,

     

    NavigationWindow is mainly used to natigate pages from one to another,As far as I know, we often need't to set the Content property of the NavigationWindow, we are more care about its Source property, as a NavigationWindow, we ofter don't set its partial  Class in the code behind.

     

    --> That is, no scrollbar appears. 

     

    You have set the HorizontalScrollBarVisibility and   VerticalScrollBarVisibility property of ScrollViewer to “Auto”, Auto means when the Content is not bigger than their container,   the scrollbar will not appear, if you want to see it whenever, you can simply set the HorizontalScrollBarVisibility and VerticalScrollBarVisibility property to “Visible”.

     

    //you can see the ScrollBar in this case
    <
    NavigationWindow 

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Source="Page1.xaml"

    Title="Window1" Height="300" Width="300">

    <!--other code-->

    <ScrollViewer Background="White" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">  

    <!--other code-->

     

     

    Page1.xaml:

      <Grid>

            <TextBlock >

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

              I am Page1

            </TextBlock>

        </Grid>

     

    In this case, the TextBlock's content can not be contained in the Window by one common row, then you will see the ScrollBar.

    -->Also, this messagebox never appears:

    Because you haven't set any event fired to show this MessageBox.

     

     


    Thanks


    Jim Zhou -MSFT
    Thursday, October 16, 2008 2:44 AM
  • Hi Jim,

    To clarify, regarding the messagebox window never displaying; this.HandlesScrolling is always false (and cannot be set to true), so the messagebox window never appears.  I was just pointing out that the NavigationWindow class seemingly does not handle scrolling. 

    Many thanks,

    Dan


    -DK
    Monday, October 20, 2008 2:39 PM