我有一个填充了usercontrols的列表框。当我填充列表框时,我会得到一个垂直滚动条,但我也会在列表框中获得一个不受欢迎的水平滚动条。我曾尝试为listboxitem创建一个转换器,但永远不会调用转换器。
<ListBox.Resources>
<local:ControlWidthConverter x:Key="widthConverter" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<!--Manages click on child controls so listitem is selected-->
<Controls:ComponentEditItem HorizontalAlignment="Left"
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBox}},
Path=ActualWidth, Converter={StaticResource widthConverter}}">
<Controls:ComponentEditItem.Triggers>
<EventTrigger RoutedEvent="GotFocus">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Duration="00:00:00" Storyboard.Target="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}" Storyboard.TargetProperty="IsSelected">
<DiscreteBooleanKeyFrame Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Controls:ComponentEditItem.Triggers>
</Controls:ComponentEditItem>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
转换器
public class ControlWidthConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double result = (double)value;
if (!Double.IsNaN(result))
{
result = result - 20;
}
else
{
result = 100D;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException("Not implemented.");
}
#endregion
}
任何人都知道为什么不调用转换器。或者如何删除水平滚动条
答案 0 :(得分:5)
这有用吗?
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Hidden"/>