我正在尝试在WPF中滚动listview控件,该控件嵌入在Grid布局控件中。我似乎无法做到这一点。任何人的想法?
顺便说一下,我在xaml标记的列表视图中设置了以下属性:
<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>
非常感谢任何帮助。
答案 0 :(得分:1)
根据我从this prior question收集的信息,如果您的网格托管在堆叠面板内,则可能会导致问题。
答案 1 :(得分:0)
尝试将VerticalAlignment
上的ListView
属性设置为Top
。如果这无助于尝试将ListView
与ScrollViewer
包裹起来(ListView.VerticalAlignment
应该有Top
值。)