1
我有一個用usercontrols填充的列表框。當我填充列表框時,我會得到一個垂直滾動條,但我也會在列表框中獲得一個unnessecary水平滾動條。我試圖爲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
}
任何人有一個想法,爲什麼轉換器不叫。或者如何刪除水平滾動條
是的,它的工作,但我沒有得到水平滾動條,如果我調整窗口大小。 – klashagelqvist 2011-12-29 10:00:06
汽車呢? – snurre 2011-12-29 10:08:07