JuP*_*JuP 2 xaml windows-runtime winrt-xaml uwp uwp-xaml
我有 ItemsControl,每个项目都有可绑定的 itemsource 和自定义 datetemplate。项目由行分隔。但是最后一项也有分隔符,这就是我的问题,如何不为最后一项渲染行。我找到了这个解决方案,但它在 WPF 中有效:
编辑: 这是我的模板:
<ItemsControl Grid.Row="1" ItemsSource="{x:Bind ViewModel.AvailableStatuses}" x:Name="Statuses">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" Padding="60,0,60,12"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding ElementName=ContentGrid, Path=DataContext.ChangeStatusCommand}" CommandParameter="{Binding}"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
<Rectangle StrokeThickness="0.4" Height="0.4" x:Name="Separator"
VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Stroke="#D1D3D4" />
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Stretch">
<Image Source="{Binding Converter={StaticResource SelectContactStatusConverter}}" Margin="0,8,12,8"/>
<TextBlock Text="{Binding Converter={StaticResource EnumContactStatusToTextConverter}}" FontSize="20" VerticalAlignment="Center" Foreground="Black"/>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
可能有几种不同的方法可以做到这一点,这是我的看法。
使用您想要的边框画笔和粗细为 ListView 的项目容器设置样式,并订阅 ContainerContentChanging 事件:
<ListView ContainerContentChanging="ListView_ContainerContentChanging">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0,1,0,0"/>
</Style>
</ListView.ItemContainerStyle>
<x:String>1</x:String>
<x:String>2</x:String>
<x:String>3</x:String>
<x:String>4</x:String>
</ListView>
Run Code Online (Sandbox Code Playgroud)
在你后面的代码中:
<ListView ContainerContentChanging="ListView_ContainerContentChanging">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0,1,0,0"/>
</Style>
</ListView.ItemContainerStyle>
<x:String>1</x:String>
<x:String>2</x:String>
<x:String>3</x:String>
<x:String>4</x:String>
</ListView>
Run Code Online (Sandbox Code Playgroud)
我决定采用这种方法有几个原因:
编辑
看起来您的意思是 ItemsControl,而不是 ListView。如果是这种情况,那么您必须按照 Depechie 的回答做一些事情,因为 ItemsControl 没有 ContainerContentChanging 事件(子类 ItemsControl 并覆盖 PrepareContainerForItemOverride),但这可能不适用于添加和删除项目的动态列表运行。如果这对您很重要,您必须尝试不同的解决方案。
| 归档时间: |
|
| 查看次数: |
3194 次 |
| 最近记录: |