zknight

zknight
- Name: [not set]
- Favorite Languages: [not set]
- Website: [not set]
- Location: [not set]
- About Me: [not set]
-
WPF Tutorial - Using The ListView, Part 3 - In Place Edit
03/27/2010 - 16:53
This seems like a great web site and I'll be spending more time here. Note to web master the edit box for posting code should be wider!! Thanks zKnight
-
WPF Tutorial - Using The ListView, Part 3 - In Place Edit
03/27/2010 - 16:50
great article!!
I'm doing the same thing but I have two listview controls on for books and one for chapters.
I have coded the Library, Book, Chapter do objects to be observableCollections and all properties are public and dependency properties. I have my data in a layered object called Library and it has one Library even tho it is a observable collections as is my list of books and list of chapters. Can I set this Library object to data context?
ex: of xml data:
<lib title="lib1">
<books>
<book title="book1">
<chapters>
<chapter title="chapter1"/>
<chapter title="chapter2"/>
</chapters>
<book>
</books>
</lib>You get the idea. I want to set one list to books and other to chapters. How do I do this and right now both list are blank showing no columns at all?
I have read both articles #1 and #3.
Sample: WPF XAML
<Window x:Class="VirtualLibrary.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VirtualLibrary"
Title="MainWindow" Closing="Window_Closing" Height="436" Width="622"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Window.Resources>
<local:BoolToVisibilityConverter x:Key="boolToVis" />
<Style TargetType="{x:Type TextBlock}" x:Key="GridBlockStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility" Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListViewItem}},
Converter={StaticResource boolToVis},
ConverterParameter=False}" />
</Style>
<Style TargetType="{x:Type FrameworkElement}" x:Key="GridEditStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility" Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListViewItem}},
Converter={StaticResource boolToVis},
ConverterParameter=True}" />
</Style>
</Window.Resources>
<Grid>
<DockPanel Name="topPanel" Margin="0,0,0,12">
<Menu Height="22" Name="appMenu" Width="Auto" DockPanel.Dock="Top" VerticalAlignment="Top">
<MenuItem Header="File" Click="FileOpen_Click"/>
<MenuItem Header="Help" />
<MenuItem Header="About" Click="About_Click"/>
</Menu>
</DockPanel>
<StackPanel Name="booksPanel" Margin="0,40,0,10">
<Label Height="28" Margin="10,10,0,0" Name="booksLabel" VerticalAlignment="Top" HorizontalAlignment="Left" Width="69">Books</Label>
<ListView ItemsSource="{Binding ElementName=This, Path=LibraryCollection.Library.Books}" Height="100" Width="580" Name="booksListView">
<GridView>
<GridViewColumn Width="140" >
<GridViewColumnHeader Click="SortClick" Tag="BookTitle" Content="Book Title"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=BookTitle}" Style="{StaticResource GridBlockStyle}"/>
<TextBox Text="{Binding Path=BookTitle}" Style="{StaticResource GridEditStyle}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="140" >
<GridViewColumnHeader Click="SortClick" Tag="BookDescription" Content="Book Description"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=BookDescription}" Style="{StaticResource GridBlockStyle}"/>
<TextBox Text="{Binding Path=BookDescription}" Style="{StaticResource GridEditStyle}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="140" >
<GridViewColumnHeader Click="SortClick" Tag="BookAuthor" Content="Book Author"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=BookAuthor}" Style="{StaticResource GridBlockStyle}"/>
<TextBox Text="{Binding Path=BookAuthor}" Style="{StaticResource GridEditStyle}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView>
<Label Height="28" Margin="10,10,0,0" Name="chaptersLabel" VerticalAlignment="Top" HorizontalAlignment="Left" Width="69">Chapters</Label>
<ListView ItemsSource="{Binding ElementName=This, Path=LibraryCollection.Books[0].Chapters}" Height="100" Width="580" Name="chaptersListView">
<GridView>
<GridViewColumn Width="140" >
<GridViewColumnHeader Click="SortClick" Tag="ChapterTitle" Content="Chapter Title"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=Chapter.ChapterTitle}" Style="{StaticResource GridBlockStyle}"/>
<TextBox Text="{Binding Path=Chapter.ChapterTitle}" Style="{StaticResource GridEditStyle}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="140" >
<GridViewColumnHeader Click="SortClick" Tag="ChapterDescription" Content="Chapter Description"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=Chapter.ChapterDescription}" Style="{StaticResource GridBlockStyle}"/>
<TextBox Text="{Binding Path=Chapter.ChapterDescription}" Style="{StaticResource GridEditStyle}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="140" >
<GridViewColumnHeader Click="SortClick" Tag="Chapter.ChapterNumber" Content="Chapter Number"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=Chapter.ChapterNumber}" Style="{StaticResource GridBlockStyle}"/>
<TextBox Text="{Binding Path=Chapter.ChapterNumber}" Style="{StaticResource GridEditStyle}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView>
</StackPanel>
<!--<Label Height="28" Margin="12,33,0,0" Name="ContentLabel" VerticalAlignment="Top" HorizontalAlignment="Left" Width="69">Contents</Label>-->
<Button Height="23" Margin="0,0,12,12" Name="exitButton" Click="ExitButton_Click" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75">Exit</Button>
<!--<TextBox Margin="12,62,12,0" Name="contentTextBox" Height="55" VerticalAlignment="Top" />-->
</Grid>
</Window>Help! zKnight
Recent Comments