带有额外列的WPF ListView

时间:2016-10-06 13:00:14

标签: wpf listview gridview

我的ListView定义如下:

<ListView Grid.Row="3" 
          ItemsSource="{Binding Items}" HorizontalAlignment="Stretch">
          <ListView.View>
                <GridView AllowsColumnReorder="False">
                     <GridView.Columns>
                          <GridViewColumn Header="Camera" DisplayMemberBinding="{Binding CameraName}" />
                           <GridViewColumn Header="Stato">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <svgc:SvgViewbox x:Name="svgIcon" Height="20"  Width="20" Stretch="Uniform" />
                                            <customUserControl:ExtendedBinding
                                                   Source="{Binding ElementName=svgIcon, Path=Source, Mode=TwoWay}"
                                                   Target="{Binding Path=IsNotConnected, Converter={StaticResource BoolToSvgPathConverter}, Mode=TwoWay}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn>
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="Retry" Width="46" IsEnabled="{Binding IsNotConnected}" Click="TryReconnection_Onclick"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView.Columns>
                    </GridView>
          </ListView.View>
</ListView>

问题是显示的ListView有一个额外的列,我无法理解原因。你有什么建议吗?

1 个答案:

答案 0 :(得分:1)

根据&#34; Auto&#34;使您的色谱柱符合您所需的确切尺寸。宽度:

  <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <ListView Grid.Column="0" ItemsSource="{Binding Items}" HorizontalAlignment="Stretch">
        <ListView.View>
            <GridView AllowsColumnReorder="False">
                <GridView.Columns>
                    <GridViewColumn Header="Camera" DisplayMemberBinding="{Binding CameraName}"  />
                    <GridViewColumn Header="Stato">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel>

                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="Retry" Width="46"  />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>