ListView ItemTemplate未填写

时间:2016-10-22 11:52:14

标签: xaml listview user-controls uwp

我为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 designer中看到的那样: image my designer

1 个答案:

答案 0 :(得分:1)

尝试将每个HorizontalContentAlignment的{​​{1}}设置为ListViewItem。同时将Stretch设置为Padding以删除蓝色条之前的间隙。

0