ListView中的全宽网格

时间:2014-09-23 10:22:36

标签: xaml windows-8.1

这是我的代码:

    <Border BorderBrush="BlueViolet" BorderThickness="9">
    <ListView x:Name="lbEOParam" ItemsSource="{Binding}" 
              Margin="0,0,0,0"                   
              HorizontalContentAlignment="Stretch">

        <ListView.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="Aqua" BorderThickness="7" >

                        <Grid HorizontalAlignment="Stretch">

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>                       
                              <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>


                    <Slider Grid.Row="0" Grid.Column="0" 
                            Minimum="{Binding MinValueDevice}" 
                            Maximum="{Binding MaxValueDevice}" 
                            Value="{Binding Value, Mode=TwoWay}"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Margin="0 0 0 0"></Slider>

                </Grid>
                </Border>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    </Border>


</Grid>

结果如下:

enter image description here

为什么我的滑块没有全宽?

1 个答案:

答案 0 :(得分:3)

您需要将ListViewItem的{​​{1}}属性设置为HorizontalContentAlignment,以使其延伸到Stretch的宽度。例如,您可以像ListView这样设置属性:

Style