代码之家  ›  专栏  ›  技术社区  ›  MicMit

wpf listview示例显示所有可能类型的列,包括hypelink和checkbox

  •  1
  • MicMit  · 技术社区  · 15 年前

    任何人都能为ListView提供一个链接,链接到包含各种列的综合示例或书籍吗?ListView绑定到可观察的集合,但为只读(主要用于为应用程序的选定行驱动某些操作的复选框除外)。

    2 回复  |  直到 15 年前
        1
  •  4
  •   Robert Rossney    15 年前

    将此粘贴到Kaxaml:

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Grid>  
        <Grid.Resources>
          <XmlDataProvider x:Key="Data">
            <x:XData>
              <Data xmlns="">
                <Item ID="1" Desc="Google" URL="http://www.google.com" Acceptable="true"/>
                <Item ID="2" Desc="StackOverflow" URL="http://www.stackoverflow.com" Acceptable="true"/>
                <Item ID="3" Desc="4chan" URL="http://www.4chan.org" Acceptable="false"/>
              </Data>
            </x:XData>
          </XmlDataProvider>
        </Grid.Resources>
        <ListView DataContext="{Binding Source={StaticResource Data}, XPath=/Data}"
          ItemsSource="{Binding XPath=Item}">
          <ListView.View>
            <GridView>
              <GridViewColumn Header="ID" DisplayMemberBinding="{Binding XPath=@ID}"/>
              <GridViewColumn Header="Description" DisplayMemberBinding="{Binding XPath=@Desc}"/>
              <GridViewColumn Header="URL">
                <GridViewColumn.CellTemplate>
                  <DataTemplate>
                    <TextBlock>
                      <Hyperlink NavigateUri="{Binding XPath=@URL}">
                        <TextBlock Text="{Binding XPath=@URL}"/>
                      </Hyperlink>
                    </TextBlock>
                  </DataTemplate>
                </GridViewColumn.CellTemplate>
              </GridViewColumn>
              <GridViewColumn Header="Acceptable">
                <GridViewColumn.CellTemplate>
                  <DataTemplate>
                    <CheckBox IsChecked="{Binding XPath=@Acceptable}"/>
                  </DataTemplate>
                </GridViewColumn.CellTemplate>
              </GridViewColumn>
            </GridView>
          </ListView.View>
          </ListView>
      </Grid>
    </Page>
    

    为了使这个(更)有用,您需要将其另存为 Page.xaml 并创建新的XAML文件:

    <NavigationWindow
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       Source="Page.xaml"/>
    

    否则,单击一个超链接将带您到有问题的页面,您将留在那里。