在gridview中添加行

时间:2010-08-31 08:19:29

标签: c# wpf

我正在尝试向网格添加垂直线条。我找到了一些例子,但没有任何作用。

<ListView  ItemsSource="{Binding Path=CheckableObjectFacilities}" x:Name="ListViewObjectFacilities" Margin="5">
    <ListView.View>
        <GridView>
            <GridViewColumn>
                <GridViewColumn.CellTemplate>
                     <DataTemplate>
                         <CheckBox IsChecked="{Binding Path=IsChecked}" Click="cboxObjectFacilities_Click" HorizontalContentAlignment="Stretch"/>
                     </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Nazwa" >
            </GridViewColumn>
            <GridViewColumn DisplayMemberBinding="{Binding Category}" Header="Kategoria" >
            </GridViewColumn>
            <GridViewColumn DisplayMemberBinding="{Binding EnglishName}" Header="EN" ></GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

1 个答案:

答案 0 :(得分:1)

按照以下网站中的示例创建GridView中的行:Designer WPF

以下是一些适用于显示系统字体信息的XAML:

<Grid>
    <Grid.Resources>
        <Style x:Key="MyItemContainerStyle" TargetType="{x:Type ListViewItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
        </Style>
    </Grid.Resources>

    <ListView 
        ItemContainerStyle="{DynamicResource MyItemContainerStyle}"
        ItemsSource="{x:Static Fonts.SystemFontFamilies}"
        x:Name="myListView"
        Width="Auto">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Name">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Border BorderBrush="#FF000000" BorderThickness="1,1,0,0" Margin="-6,-2,-6,-2">
                                <StackPanel Margin="6,2,6,2">
                                    <TextBlock Text="{Binding Source}"/>
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Line Spacing">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <Border BorderBrush="#FF000000" BorderThickness="1,1,0,0" Margin="-6,-2,-6,-2">
                                <StackPanel Margin="6,2,6,2">
                                    <TextBlock Text="{Binding LineSpacing}"/>
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Sample">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Border BorderBrush="#FF000000" BorderThickness="1,1,1,0" Margin="-6,-2,-6,-2">
                                <StackPanel Margin="6,2,6,2">
                                    <TextBlock FontFamily="{Binding}" FontSize="20"
                                       Text="ABCDEFGabcdefg" />
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>