views:

141

answers:

2

Hi There

I am trying to scroll a listview control in WPF which is embedded in a Grid layout control. I can't seem to achieve this. Any ideas anyone?

By the way i have set the following properties on the list view in the xaml markup:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <!--Top Area-->
    <GroupBox Grid.Row="0" Header="Price, Volume and Ratio Stats">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <!--Row 1-->
            <TextBlock x:Name="tbSellInstrumentCode" Grid.Column="0" Grid.Row="0">Sell Share</TextBlock>
            <TextBox x:Name="txtSellInstrumentCode" Grid.Column="1" Grid.Row="0" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbBuyInstrumentCode" Grid.Column="2" Grid.Row="0">Buy Share</TextBlock>
            <TextBox x:Name="txtBuyInstrumentCode" Grid.Column="3" Grid.Row="0" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbTargetPriceRatio" Grid.Column="4" Grid.Row="0">Target Trigger</TextBlock>
            <TextBox x:Name="txtTargetPriceRatio" Grid.Column="5" Grid.Row="0" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbTradedPriceRatio" Grid.Column="6" Grid.Row="0">Traded Price Ratio</TextBlock>
            <TextBox x:Name="txtTradedPriceRatio" Grid.Column="7" Grid.Row="0" IsEnabled="False"></TextBox>
            <!--Row 2-->
            <TextBlock x:Name="tbBidPrice" Grid.Column="0" Grid.Row="1">Bid Price</TextBlock>
            <TextBox x:Name="txtBidPrice" Grid.Column="1" Grid.Row="1" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbAskPrice" Grid.Column="2" Grid.Row="1">Ask Price</TextBlock>
            <TextBox x:Name="txtAskPrice" Grid.Column="3" Grid.Row="1" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbMarketPriceRatio" Grid.Column="4" Grid.Row="1">Market Trigger</TextBlock>
            <TextBox x:Name="txtMarketPriceRatio" Grid.Column="5" Grid.Row="1" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbTradedVolumeRatio" Grid.Column="6" Grid.Row="1">Traded Volume Ratio</TextBlock>
            <TextBox x:Name="txtTradedVolumeRatio" Grid.Column="7" Grid.Row="1" IsEnabled="False"></TextBox>
            <!--Row 3-->
            <TextBlock x:Name="tbBidVolume" Grid.Column="0" Grid.Row="2">Bid Volume</TextBlock>
            <TextBox x:Name="txtBidVolume" Grid.Column="1" Grid.Row="2" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbAskVolume" Grid.Column="2" Grid.Row="2">Ask Volume</TextBlock>
            <TextBox x:Name="txtAskVolume" Grid.Column="3" Grid.Row="2" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbTradedSpread" Grid.Column="4" Grid.Row="2">Traded Spread</TextBlock>
            <TextBox x:Name="txtTradedSpread" Grid.Column="5" Grid.Row="2" IsEnabled="False"></TextBox>
            <TextBlock x:Name="tbTradedAmountRatio" Grid.Column="6" Grid.Row="2">Traded Amount Ratio</TextBlock>
            <TextBox x:Name="txtTradedAmountRatio" Grid.Column="7" Grid.Row="2" IsEnabled="False"></TextBox>
        </Grid>
    </GroupBox>
    <!--Middle Area-->
    <GroupBox Grid.Row="1" Header="Average Price, Total Volumes and Averages Stats">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <!--Row 1-->
            <TextBlock Grid.Column="0" Grid.Row="0">Total Sell Volume</TextBlock>
            <TextBox x:Name="txtTotalSellVolume" Grid.Column="1" Grid.Row="0" IsEnabled="False"></TextBox>
            <TextBlock Grid.Column="2" Grid.Row="0">Total Buy Volume</TextBlock>
            <TextBox x:Name="txtTotalBuyVolume" Grid.Column="3" Grid.Row="0" IsEnabled="False"></TextBox>
            <!--Row 2-->
            <TextBlock Grid.Column="0" Grid.Row="1">Total Sell Amount (ZAR)</TextBlock>
            <TextBox x:Name="txtTotalSellAmount" Grid.Column="1" Grid.Row="1" IsEnabled="False"></TextBox>
            <TextBlock Grid.Column="2" Grid.Row="1">Total Buy Amount (ZAR)</TextBlock>
            <TextBox x:Name="txtTotalBuyAmount" Grid.Column="3" Grid.Row="1" IsEnabled="False"></TextBox>
            <!--Row 3-->
            <TextBlock Grid.Column="0" Grid.Row="2">Average Sell Price (ZAR)</TextBlock>
            <TextBox x:Name="txtAverageSellPrice" Grid.Column="1" Grid.Row="2" IsEnabled="False"></TextBox>
            <TextBlock Grid.Column="2" Grid.Row="2">Average Buy Price (ZAR)</TextBlock>
            <TextBox x:Name="txtAverageBuyPrice" Grid.Column="3" Grid.Row="2" IsEnabled="False"></TextBox>
            <!--Row 4-->
            <TextBlock Grid.Column="0" Grid.Row="3">Number of Unfilled Orders</TextBlock>
            <TextBox x:Name="txtNumberOfUnfilledOrders" Grid.Column="1" Grid.Row="3" IsEnabled="False"></TextBox>
            <TextBlock Grid.Column="2" Grid.Row="3">Slippage (ZAR)</TextBlock>
            <TextBox x:Name="txtSlippage" Grid.Column="3" Grid.Row="3" IsEnabled="False"></TextBox>
        </Grid>
    </GroupBox>
    <Grid Grid.Row="2">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <ListView x:Name="lvSellTrades" Grid.Column="0" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" VerticalAlignment="Top">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Date, StringFormat=hh:mm:ss tt}" Header="Date"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=AccountCode}" Header="Account Code"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Price, StringFormat={}{0:N0}}" Header="Sell Price"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Volume, StringFormat={}{0:N0}}" Header="Sell Volume"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Amount, StringFormat=R {0:N2}}" Header="Amount"></GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <ListView x:Name="lvBuyTrades" Grid.Column="1" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" VerticalAlignment="Top">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Date, StringFormat=hh:mm:ss tt}" Header="Date"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=AccountCode}" Header="Account Code"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Price, StringFormat={}{0:N0}}" Header="Buy Price"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Volume, StringFormat={}{0:N0}}" Header="Buy Volume"></GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Amount, StringFormat=R {0:N2}}" Header="Amount"></GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Grid>

Any help would be much appreciated.

A: 

Try to set VerticalAlignment property on ListView to "Top". If this does not help try to wrap ListView with ScrollViewer (ListView.VerticalAlignment should have "Top" value)

Lolo
Tried that - no difference. See edited code of original post.
c0D3l0g1
For me it works without ScrollViewer with no problem in VS2010.
Lolo
+1  A: 

From what i've gathered from this prior question, If your grid is hosted inside a stackpanel, it could cause issues.

Val
I was using a DockPanel to host the Grid. Got rid of that and replaced it with another Grid. Still the same effect.
c0D3l0g1
I have edited the original post, with complete XAML code.
c0D3l0g1
I don't see any issues with the XAML, could you also describe the nature of your issue a little clearer. I'm unsure exactly what functionality you're hoping to achieve or what functionality currently have
Val
All i am trying to do is to get automatic vertical scroll functionality for lvSellTrades and lvBuyTrades. Currently, when the listviews exceed the visible areas, they do not display vertical scrollbars.
c0D3l0g1
Hi Val, your answer is correct. The XAML from above was in a user control which was hosted in another window, and that windows layout control was a stackpanel. Changed it and everything works great! Thanks for your help.
c0D3l0g1
No worries. Glad its working.
Val