2
我想要的:要讓水平滾動條出現。我會稍微編輯它,只是爲了適應應用程序的其他風格方案,但不是太多。流體列表框上的水平滾動條
我有什麼
下面是列表框以現在的代碼。除滾動條不出現外,一切都運行完美。你可能會說......「以及你沒有滾動查看器的任何地方」,但我曾嘗試在很多地方插入scrollviewer,但仍然沒有運氣。
列表框代碼:
<ListBox ItemsSource="{Binding Items}" ItemTemplate="{StaticResource itemsdatatemplate}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" ItemsPanel="{StaticResource HorizontalListBoxTemplate}" ItemContainerStyle="{StaticResource TransparentListBox}" VerticalAlignment="Center" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
的 'TransparentListBox'(以閉嘴選擇背景色):
<Style x:Key="TransparentListBox" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid>
<Border x:Name="HoverBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
<Border x:Name="SelectedBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
<ContentPresenter></ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
水平列表框(使列表框水平,而不是標準垂直)
<ItemsPanelTemplate x:Key="HorizontalListBoxTemplate">
<StackPanel Orientation="Horizontal">
</StackPanel>
</ItemsPanelTemplate>
的DataTemplate的(實際顯示的項目)
<DataTemplate x:Key="itemsdatatemplate">
<local:ListItemControl HorizontalAlignment="Left" VerticalAlignment="Top" DataContext="{Binding}"/>
</DataTemplate>
我有一種感覺它的將是一個簡單的加法,而是在此先感謝。
更新
它看起來像現在滾動條出現做此:
<Style x:Key="ScrollingListBox" TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Visible">
<ItemsPresenter></ItemsPresenter>
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
但他們並沒有相應的功能。他們覺得...破碎。但是,如果要定義網格的靜態寬度(比如說300),那麼ScrollViewer的表現完美。現在我有一個完全流暢的佈局(意思是可以填充的東西),對於scrollviewers來說這是不可接受的嗎?
這是要包含在「樣式」列表框中,是否正確?事實上,這確實顯示滾動條,但它沒有鏈接到列表框。它基本上是一個不可滾動的滾動條,並且沒有結點來回移動。 – Peanut 2011-03-24 01:13:11
我更新了這個例子。滾動查看器進入ListBox的ControlTemplate內部。也許只是刪除HorizontalScrollBarVisibility屬性,以便ListBox控制它。當內容溢出時,「nub」將出現。如果您的內容不超過滾動查看器的寬度,您將無法滾動。 – Laith 2011-03-24 01:44:52
實際上,將滾動條放在每個列表框的項目中,而不是一個大滾動條來控制列表框本身。注意'TargetType'。它的目標是一個ListBoxItem。謝謝。 – Peanut 2011-03-24 03:59:26