여기 표준 ListBox 컨트롤을 사용하여, 그것을 할 한 가지 방법입니다 :
첫째, 우리는 다음/이전 버튼과리스트 박스의 한 쌍을 필요로한다. 우리는 목록 상자가 ItemsPanel을 변경하여 수평으로 해당 항목을 배치 할 : 우리는 Template를 검색하고 찾을 VisualTreeHelper를 사용하여 목록 상자에서
<DockPanel Width="200" >
<Button x:Name="_prev" Content="<<" />
<Button x:Name="_next" Content=">>" DockPanel.Dock="Right" />
<ListBox x:Name="_myList" Loaded="OnMyListLoaded" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<TextBlock Text="Image1 " />
<TextBlock Text="Image2 " />
<TextBlock Text="Image3 " />
<TextBlock Text="Image4 " />
<TextBlock Text="Image5 " />
<TextBlock Text="Image6 " />
<TextBlock Text="Image7 " />
</ListBox>
</DockPanel>
'로드 이벤트를 자사의 내장에서 ScrollViewer. 일단 우리가 찾으면 우리가 만든 두 개의 버튼에 연결합니다.
private void OnMyListLoaded(object sender, RoutedEventArgs e)
{
var scroller = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(_myList, 0), 0) as ScrollViewer;
if (scroller != null)
{
_prev.Command = ScrollBar.LineLeftCommand;
_prev.CommandTarget = scroller;
_next.Command = ScrollBar.LineRightCommand;
_next.CommandTarget = scroller;
scroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
}
}
"ScrollBar"라는 이름이 있습니다. 현재 컨텍스트에 존재하지 않습니다 ... 내가 참조를 가져올 필요가 있습니까? – 0070
@ 0070 - 새로운 참조는 필요 없지만 코드 파일의 맨 위에있는 다른 using 문과 함께 다른 "using"문이 필요합니다. ** using System.Windows.Controls.Primitives; ** – Sphinxxx