WPF ListView
は、常に見えるフッターで拡張する必要があります。 フッターはヘッダーのように動作し、スクロールしないでください。 次のXAMLは、ListViewコントロールのScrollViewerのを操縦するの背後にあるコードにリンクされている外部ScrollViewer
使用しています。この背後にあるコードでListViewの推奨サイズにバインドするにはどうすればよいですか?
<Window x:Class="LayoutTests.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="125" Width="176">
<Grid>
<StackPanel>
<ListView Name="L" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
<ListViewItem Content="Brown brownie with a preference for white wheat."/>
<ListViewItem Content="Red Redish with a taste for oliv olives."/>
</ListView>
<ScrollViewer CanContentScroll="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" ScrollChanged="ScrollViewer_ScrollChanged">
<!-- Would like to bind Rectangle.Width to the preferred width of L -->
<Rectangle Height="20" Width="500" Fill="Red"/>
</ScrollViewer>
</StackPanel>
</Grid>
</Window>
は次のようになります。
private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
var bottomScrollViewer = sender as ScrollViewer;
var listScrollViewer = GetScrollViewer(L) as ScrollViewer;
if (listScrollViewer != null && bottomScrollViewer != null)
listScrollViewer.ScrollToHorizontalOffset(bottomScrollViewer.HorizontalOffset);
}
GetScrollViewer()
は(次のように定義されていますが、 )重要でない:
public static DependencyObject GetScrollViewer(DependencyObject depObj)
{
if (depObj is ScrollViewer)
{ return depObj; }
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = GetScrollViewer(child);
if (result == null) { continue; }
else { return result; }
}
return null;
}
ListView
のScrollViewer
は明らかにABを知っていますその子の好ましい幅を外します。 問題は、その幅にバインドする方法が見つからないことです。したがって、ここにあります:
Rectangle.Width
をListView
の好ましいサイズにバインドする方法を教えてください。
また、常に表示されるフッタをListView
に含めるにはどうすればよいですか?
あなたのバインディングの設定は非常に興味深いです - 私はその中で{{}でコードを指定することで内容が混乱する可能性があることを知りませんでした。その名前はありますか?現在、私にとってはうまくいかず、スクロールバーが表示されません。今すぐデバッグする。 – Pascal
奇妙な - その幅は何ですか? ([Snoopユーティリティ](http://snoopwpf.codeplex.com/)を使用して参照できます)。 – Vlad
さて、ダミーコンバータを指定して(そして 'Convert'メソッドでブレークポイントを設定することによって)バインディングをデバッグすることができます。 – Vlad