WPF ListView with GridViewColumn and DataTemplate

♀尐吖头ヾ 提交于 2019-11-27 19:45:38

You need to define the data template as CellTemplate for your column:

<ListView x:Name="lbDatabases" Height="138" Width="498" Canvas.Left="44" Canvas.Top="146"  >
    <ListView.View >
        <GridView >
            <GridViewColumn Header="Databases" Width="498">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox IsChecked="{Binding IsActive}" Checked="AnyChange" Unchecked="AnyChange"  Style="{x:Null}" Content="{Binding DbName}"
                                  Width="{Binding CheckWidth}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>
Ready Cent

ok after struggling all morning I figured it out. They key here is to use a CellTemplate:

 <ListView x:Name="lbDatabases" Height="138" Width="498" Canvas.Left="44" Canvas.Top="146"  Style="{StaticResource ListViewStyle}">
        <ListView.View >
            <GridView>
                <GridViewColumn Header="Databases" Width="498">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                        <CheckBox IsChecked="{Binding IsActive}" Checked="AnyChange" Unchecked="AnyChange"  Style="{x:Null}" Content="{Binding DbName}"
                   Width="{Binding CheckWidth}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>            
    </ListView>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!