WPF ListView example showing all possible kinds of columns including hypelink and checkbox
Could anyone help with a link to comprehensive example or book with all pos开发者_如何学Csible kinds of columns for ListView. ListView is bound to Observable collection but read-only ( except checkboxes which are primarily to drive certain actions for selected rows for the application ).
Paste this into 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>
To make this (more) useful, you'll want to save it as Page.xaml
and create a new XAML file:
<NavigationWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Source="Page.xaml"/>
Otherwise, clicking on a hyperlink will take you to the page in question, where you will remain.
Check out this links:
http://www.c-sharpcorner.com/UploadFile/mahesh/WPFListView09092008224322PM/WPFListView.aspx http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1
精彩评论