我使用的是star converter to have relative sized listview columns,但我目前的问题是,如果滚动条可见,则不会考虑这一点。我尝试在代码中添加如下内容:
var scroll = FindVisualChild<ScrollViewer>(listView);
var offset = 0.0;
if (scroll.ComputedVerticalScrollBarVisibility == Visibility.Visible)
offset = SystemParameters.ScrollWidth + 5;
但是,大小调整是在滚动条可见性之前完成的,滚动始终显示为Collapsed
。
所以,我的问题是,如何适当调整列的大小。我曾尝试在ScrollViewer.ComputedVerticalScrollBarVisibility
添加触发器,但在那里没有取得任何成功。我尝试使用custom code based off of this link,但目前总是以空白列表视图结尾(可能是由于使用ItemsPresenter的listview,但我目前不确定)。
以下是我尝试过的listview设置:
<Style x:Key="{x:Type ListView}" TargetType="ListView">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<Border Name="Border" BorderThickness="0" BorderBrush="#999999" >
<ScrollViewer x:Name="blah" >
<ItemsPresenter />
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger SourceName="blah" Property="ComputedVerticalScrollBarVisibility" Value="Hidden">
<Setter Property="BorderBrush" Value="Aqua"/>
<Setter Property="BorderThickness" Value="10"/>
</Trigger>
<Trigger SourceName="blah" Property="ComputedVerticalScrollBarVisibility" Value="Collapsed">
<Setter Property="BorderBrush" Value="Orange"/>
<Setter Property="BorderThickness" Value="10"/>
</Trigger>
<Trigger SourceName="blah" Property="ComputedVerticalScrollBarVisibility" Value="Visible">
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="10"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Background" Value="#BBBBBB"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
设置者只是为了看它是否有效......但它们根本就没有设置