gpt4 book ai didi

xaml - ListView ItemTemplate 未填充

转载 作者:行者123 更新时间:2023-12-02 20:56:15 26 4
gpt4 key购买 nike

我为 ListViewItem 创建了一个模板。

它并没有填满所有的空间。

我的模板如下:

<UserControl
x:Class="AgendaUWP.Styles.Template.ItemTemplateContatti"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AgendaUWP.Styles.Template"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="100"
d:DesignWidth="400">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3" />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Background="CornflowerBlue" Grid.Column="0" Width="3" Margin="0 0 0 0" VerticalAlignment="Stretch"/>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="10 0 0 0" HorizontalAlignment="Stretch" VerticalAlignment="Center" >
<TextBlock Text="{Binding Tipo}" FontWeight="Thin" FontSize="10" TextAlignment="Center" />
<TextBlock Text="{Binding Descrizione}" FontWeight="SemiBold" FontSize="16" TextAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Stretch" >
<StackPanel Orientation="Horizontal" Margin="0 10 0 10" >
<SymbolIcon Symbol="Phone" Margin="10 0 10 0"></SymbolIcon>
<TextBlock Text="{Binding Telefono}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 10 0 10">
<SymbolIcon Symbol="Mail" Margin="10 0 10 0"></SymbolIcon>
<TextBlock Text="{Binding Email}" />
</StackPanel>
</StackPanel>

</Grid>

使用方法如下:

                        <ListView x:Name="listaContatti"
IsItemClickEnabled="True" MaxHeight="200"
SelectedItem="{Binding ClientiContatti,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding ListaClientiContatti,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<template:ItemTemplateContatti />
</DataTemplate>
</ListViewItemTemplate>
</ListView>

这是我的结果: image my result

我想看到线条的开头、蓝色边框和两个 StackPanel,就像您在 Visual Studio 设计器中看到的那样: image my designer

最佳答案

尝试将每个 ListViewItemHorizo​​ntalContentAlignment 设置为 Stretch。还将 Padding 设置为 0 以删除蓝条之前的间隙。

<ListView x:Name="listaContatti"
IsItemClickEnabled="True" MaxHeight="200"
SelectedItem="{Binding ClientiContatti,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding ListaClientiContatti,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<template:ItemTemplateContatti />
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
</Style>
</ListView.ItemContainerStyle>
</ListView>

关于xaml - ListView ItemTemplate 未填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40191822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com