Custom view listview Binding WPF - wpf

Hi I have next XAML markup (just a piece of course):
<Window.Resources>
<GridView x:Key="gridview">
<GridViewColumn Width="200" DisplayMemberBinding="{Binding Title}">
<GridViewColumnHeader Content="Titel" Tag="Title" Click="SortClick"/>
</GridViewColumn>
<GridViewColumn Width="200" DisplayMemberBinding="{Binding Artist}">
<GridViewColumnHeader Content="Artiest" Tag="Artist" Click="SortClick"/>
</GridViewColumn>
<GridViewColumn Width="200" DisplayMemberBinding="{Binding Album}">
<GridViewColumnHeader Content="Album" Tag="Album" Click="SortClick"/>
</GridViewColumn>
<GridViewColumn Width="50" DisplayMemberBinding="{Binding Genre}">
<GridViewColumnHeader Content="Genre" Tag="Genre" Click="SortClick"/>
</GridViewColumn>
<GridViewColumn Width="50" DisplayMemberBinding="{Binding Jaar}">
<GridViewColumnHeader Content="Jaar" Tag="Jaar" Click="SortClick"/>
</GridViewColumn>
</GridView>
<my:IdToImageConverter x:Key="idToImageConverter" />
<DataTemplate x:Key="iconTemplate">
...
</DataTemplate>
<my:PlainView x:Key="iconView"
ItemTemplate="{StaticResource iconTemplate}"
ItemWidth="300"/>
</Window.Resources>
<Grid>
<ListView Name="LibView" ItemsSource="{Binding ElementName=win, Path=Biblio}"/>
</Grid>
Biblio is the observable collection containing the elements for LibView
iconView and gridview are the views i use for LibView. This works perfectly.
Now i want to add a view wich groups every element by "Artist", and i want to display this like:
Artist1 - TitleA - AlbumA
- TitleB - AlbumB
- TitleC - AlbumC
Artist2 - TitleD - AlbumD
...
I guess i have to make some kind of template but i don't even know if this is possible using XAML.

It sound like you want a GroupStyle - this might explain:
http://bea.stollnitz.com/blog/?p=17
There are many examples - try a search on wpf groupstyle :)

Related

Populating a list view, from view model class in WPF

I am trying to add a list of model objects to my list view
This is my View Code which contains a list view as a Grid View
<ListView Grid.Row="8" Grid.ColumnSpan="3" Name="EmployeeDetailsListView">
<ListView.View>
<GridView>
<GridViewColumn Header="{x:Static resx:Resources.String1}" DisplayMemberBinding="{Binding EmployeeID}"></GridViewColumn>
<GridViewColumn Header="{x:Static resx:Resources.String2}" DisplayMemberBinding="{Binding FirstName}"></GridViewColumn>
<GridViewColumn Header="{x:Static resx:Resources.String3}" DisplayMemberBinding="{Binding LastName}"></GridViewColumn>
<GridViewColumn Header="{x:Static resx:Resources.String10}" DisplayMemberBinding="{Binding Gender}"></GridViewColumn>
<GridViewColumn Header="{x:Static resx:Resources.String11}" DisplayMemberBinding="{Binding Phone}"></GridViewColumn>
<GridViewColumn Header="{x:Static resx:Resources.String7}" DisplayMemberBinding="{Binding Phone}" ></GridViewColumn>
<GridViewColumn Header="{x:Static resx:Resources.String8}" DisplayMemberBinding="{Binding Phone}" ></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
My View Model Contains the following code
List<EmployeeModel> eList = new List<EmployeeModel>();
eList.Add(EmployeeModel);
EmployeeDetailsListView.ItemsSource = eList;
I am trying to populate the List View from the View Model, but the ListView is not getting recognised in the ViewModel Class
I am getting the following error
"The name 'EmployeeDetailsListView' does not exist in the current context "
I want to know how to access ListView present in View.xaml from my ViewModel, so that I can populate the list view.
Thanks in Advance :)

Is there Expression Dark theme for WPF DataGrid?

I am just wondering if there is Expression Dark theme for WPF DataGrid?
Or how to adjust it for WPF DataGrid?
Any links?
UPDATES:
It's possible replace WPF DataGrid to WPF ListView and Expressaion Dark theme applies good.
<ListView Name="MainTable" >
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Filename}" Width="140" Header="{lex:LocTextExtension Key=Name, Dict=Resources, Assembly=PreShow.Player}" />
<GridViewColumn DisplayMemberBinding="{Binding IsSuccess}" Width="60" Header="{lex:LocTextExtension Key=Success, Dict=Resources, Assembly=PreShow.Player}" />
<GridViewColumn DisplayMemberBinding="{Binding Downloaded}" Width="140" Header="{lex:LocTextExtension Key=Time, Dict=Resources, Assembly=PreShow.Player}" />
<GridViewColumn DisplayMemberBinding="{Binding IsDownloading}" Width="100" Header="{lex:LocTextExtension Key=IsDownloading, Dict=Resources, Assembly=PreShow.Player}" />
<GridViewColumn DisplayMemberBinding="{Binding URL}" Width="Auto" Header="URL" />
</GridView>
</ListView.View>
</ListView>
Here you go:
http://datagridthemesfromsl.codeplex.com/
A reusable theme library for the WPF DataGrid, so that it can look and handle like the Silverlight DataGrid.
Themed after ExpressionLight, ExpressionDark, WhistlerBlue, etc.
Features:
SelectedCells attached property: data binding selected cells to your MVVM ViewModels.
Horizontal scrolling with mouse tilt wheel.
Please see documentation for usage.
This project was developed purely in code (XML/XAML and C#), and not in some GUI "designer"...

WPF Listview flickering problem

I am using a thread for reading the file and make a array of objects from the data read.A seperate thread for filtering records based on some filters is being used.
I am using listview to show data for dataset I get as per above.
While laoding a file everthing seems good but when I search,the problem exists.
while searching when I apply filters for the 1st time, everything is okay. Now again when I apply filters, data of the previous search is show for 1 sec(kind of flicker) and then the new data according to current filter is rendered.
I am using dispatcher for updating UI.
Before I bind any data, I try to clear ListView ItemSource by setting it to null
XAML code i am using is :
{
<ListView Name="listView1"
Grid.Row="0"
ItemsSource= "{Binding ElementName=Window1, Path=Entries}"
AllowDrop="True"
SelectionChanged="listView1_SelectionChanged"
Drop="listView1_Drop">
<ListView.View>
<GridView x:Name="GridView1" >
<GridViewColumn Header="Item" DisplayMemberBinding="{Binding Item}" />
<GridViewColumn Header="TimeStamp" DisplayMemberBinding="{Binding TimeStamp}"/>
<GridViewColumn Header="">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Image}" Width="16" Height="16" VerticalAlignment="Top" HorizontalAlignment="Left"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Level" DisplayMemberBinding="{Binding Level}"/>
<GridViewColumn Header="Class" DisplayMemberBinding="{Binding Class}"/>
<GridViewColumn Header="Message" DisplayMemberBinding="{Binding Message1}" Width="250" />
</GridView>
</ListView.View>
</ListView>
}
Code Behind is :
private void ClearListView()
{
UpdateList update = new UpdateList(UpdateListData);
List<LogEntry> searcheddata = new List<LogEntry>();
searcheddata = null;
listView1.ItemsSource = null;
listView1.Items.Clear();
listView1.Items.Refresh();
pdDispatcher.BeginInvoke(update, DispatcherPriority.Render, searcheddata);
}
psdispatcher is the dispatcher used to update the UI & searchdata is function to assign datasource to listview

How to show properties of a list in a list in a listview?

I am implementing an application in wpf , MVVM pattern.
I want to implement a listview with objects. These objects contains a list. On default this list contains only 1 object. But in the listview, I want to show that certain object. So the properties of the object in the list. This is my first problem.
But I also have to be able to have more objects in this list. My second problem is that i don't really know how to realise this? And i also have to show the properties of these objects in the listview.
Maybe a treeview? but i don't get how that i got to begin on this..
Someone with some ideas?
You can arbitrarily nest DataTemplates, e.g.
<ListView ItemsSource="{Binding Data}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
<!-- Internal Manchines list gets its own ListView -->
<GridViewColumn Header="Machines">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding Machines}">
<ListView.View>
<GridView>
<GridViewColumn Header="Model" DisplayMemberBinding="{Binding Model}"/>
<GridViewColumn Header="Manufacturer" DisplayMemberBinding="{Binding Manufacturer}"/>
</GridView>
</ListView.View>
</ListView>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Occupation" DisplayMemberBinding="{Binding Occupation}"/>
<GridViewColumn Header="Status" DisplayMemberBinding="{Binding Status}"/>
</GridView>
</ListView.View>
</ListView>
This can be improved in terms of alignment, e.g. you could set up a Grid in the DataTemplate with a shared size column to make all lists the same width (making the internal columns align might be a bit hard though)
Further you could define a style to collapse empty lists (which otherwise would show the header without items).

how to dynamically create controls for GridView DataTemplate in WPF?

I have a GridView control:
<GridView>
<GridViewColumn Header="Name" Width="500">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding TypeName}" Header="Type" Width="100" />
</GridView>
for the first column("name"), I would like to have a mechanism that when every record is binded, will be a way(e.g. event), so that I can dynamically add controls to the StackPanel.
for example, my data has a column called AnimalType, if it is a cat, I will add an image to the StackPanel; if it is a cow, I will put a media element to play a movie; if it is a dog, I will put a hyper link, etc.
How can I do that?
Take a look at the DataTemplateSelector class....
like here:
http://www.wpftutorial.net/DataTemplates.html

Resources