CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2016
    Posts
    5

    Question WPF/XAML Cannot Get Scrollbars to Actually work on DataGrid---visible but don't work

    The vertical and horizontal scrollbars are showing on my DataGrid, but they don't actually do anything when you click on them. They appear grayed out and do nothing. I have seen some code where I have to encapsulate the DataGrid in a Scrollbar viewer and/or ScrollBar but as of right now I have not been able to get any of the XAML to work properly with it...if anyone could lend me a hand on this it would be greatly appreciated, I am unsure what I am doing incorrectly...switching from WinForms to WPF has been mostly awesome, as there are a lot of things that are much faster and easier in WPF, but then I run into things like this that were handled automatically in WinForms(my datagrid always had both scrollbars enabled and was able to be sorted by any column automatically without me doing anything---neither of these is the case in WPF). I am mostly learning XAML/WPF on the fly and have figured out most things I have had questions on, including writing a custom Event Handler for a mouse button click on a text box because the normal one would fire anytime a button was pushed anywhere instead of just on the textbox, but this one has eluded me and I've spent many hours trying to resolve this unsuccessfully...

    Here is my XAML:
    Code:
    <Page x:Class="GenerationDraft"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:local="clr-namespace:WPFGeneration"
          mc:Ignorable="d"
          d:DesignHeight="1600" d:DesignWidth="2400"
          Title="Generation: Draft Players">
    
        <Grid x:Name="DraftGenGrid" Height="Auto" Width="Auto" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Image x:Name="GoalLineStandPic" Source="JENK10.png" MaxHeight="1600" MaxWidth="2400" Opacity="0.4" Stretch="Fill" Grid.RowSpan="3" />
           
            <DataGrid x:Name="DraftGrid" HorizontalAlignment="Center"  ItemsSource="{Binding}" MaxHeight="300" MaxWidth="2400"  Grid.Row="2"/>
          
            <TextBlock x:Name="GenDraftText" FontSize="30" FontStyle="Normal" FontFamily="Times New Roman Bold" Text="Goal Line Stand College Draft Creator" Margin="5,5,0,0" Grid.RowSpan="3"></TextBlock>
            <Button x:Name="CreateDraft" Content="Create Draft Class" HorizontalAlignment="Left" Margin="10,140,0,0" Style="{DynamicResource SimpleButton}" VerticalAlignment="Top" Width="145" Height="50" Opacity="0.7">
                <Button.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFEEEEEE" Offset="0" />
                        <GradientStop Color="#FF1A21B4" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button x:Name="OpenDB" Content="Choose DataBase To Open" HorizontalAlignment="Left" Margin="10,80,0,0" Style="{DynamicResource SimpleButton}" VerticalAlignment="Top" Width="145" Height="50" Opacity="0.7">
                <Button.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFEEEEEE" Offset="0" />
                        <GradientStop Color="#FF1A21B4" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <TextBox x:Name="CreateDraftTextBox" HorizontalAlignment="Left" Height="23" Margin="9,194,0,0" Style="{DynamicResource SimpleTextBox}" TextWrapping="Wrap" Text="Enter Num Players To Create" VerticalAlignment="Top" Width="186" Opacity="0.6" Background="#B54B79C6" IsReadOnly="False"
                     MouseDown="Button_MouseDown">
            </TextBox>
    
            <TextBlock x:Name="DepthPositions" HorizontalAlignment="Left" Width="140" Margin="9,237,0,0" RenderTransformOrigin="0.521,0.722"><Run Text="QB Depth:" /><LineBreak /><Run Text="RB Depth:" /><LineBreak /><Run Text="FB Depth:" /><LineBreak />
                <Run Text="WR Depth:" /><LineBreak /><Run Text="TE Depth:" /><LineBreak /><Run Text="OT Depth:" /><LineBreak /><Run Text="C Depth:" /><LineBreak /><Run Text="OG Depth:" /><LineBreak /><Run Text="DE Depth:" /><LineBreak /><Run Text="DT Depth:" />
                <LineBreak /><Run Text="OLB Depth:" /><LineBreak /><Run Text="ILB Depth:" /><LineBreak /><Run Text="CB Depth:" /><LineBreak /><Run Text="FS Depth:" /><LineBreak /><Run Text="SS Depth:" /><LineBreak /><Run Text="K Depth:" /><LineBreak /><Run Text="P Depth:" />
                <LineBreak /><Run /></TextBlock>
        </Grid>
    </Page>

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: WPF/XAML Cannot Get Scrollbars to Actually work on DataGrid---visible but don't w

    Try making the grid height and width fixed values instead of auto.

  3. #3
    Join Date
    Feb 2016
    Posts
    5

    Re: WPF/XAML Cannot Get Scrollbars to Actually work on DataGrid---visible but don't w

    Quote Originally Posted by Arjay View Post
    Try making the grid height and width fixed values instead of auto.
    I'll try it again...initially they were fixed values, I changed them to "*" then "auto" and neither worked...

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: WPF/XAML Cannot Get Scrollbars to Actually work on DataGrid---visible but don't w

    I'd try a test project and simplify the contents of the grid. Get the scrolling working and then figure out why it doesn't work in your real project.

  5. #5
    Join Date
    Feb 2016
    Posts
    5

    Re: WPF/XAML Cannot Get Scrollbars to Actually work on DataGrid---visible but don't w

    I got everything working by putting a few Stackpanels inside the grid for the controls to be inside of...works great, and I'm loving the versatility of WPF more and more as I learn new things...

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: WPF/XAML Cannot Get Scrollbars to Actually work on DataGrid---visible but don't w

    Great.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured