C# WPF XAML Problem with icon in GridViewColumn - c#

I've created a ListView with a GridView component in it. Now trying to fill one of the cells with an icon (PNG) like in the code sample below (save_icon.png):
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
<GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
<GridViewColumn Width="Auto">
<Image Source="save_icon.png" />
</GridViewColumn>
</GridView>
</ListView.View>
Visual Studio gives me an error on the line, where i put the icon into the column (ERROR: "Error 35: The file save_icon.png is not part of the project or its 'Build Action' property is not set to 'Resource'.") I added the icon to the project as a resource and when i start the app, everything works (the icon appears at the right place). But the WPF designer window can't be reloaded and i'm not able to see changes in the designer, when i change the XAML code.
Can somebody explain this error or am i doing something wrong?
Thanks for every hint in advance!

I found a solution for my problem. Just use a Cell- and DataTemplate inside of a GridViewColumn. The follwoing XAML-Code-Snippet does exactly what i need and the wpf designer reloads without any problems:
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
<GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
<GridViewColumn Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="Resources\saveicon.png"></Image>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>

I believe it is because you have an underscore in your image filename. Try removing the underscore and rebuilding.

Related

is there any way to show the columns of a GridView in different rows?

I have a ListView that is going to show some values of a Google calendar event, the application let you see what events do you have for one specific date, and you can add more, edit, or delete the events.
By the moment, i am showing all the events just for testing, and i am using a gridview for the properties to reorder and the headers, but the event have too much values and is too wide, what i want is split this columns in two rows
Column A, Column B, Column C
info info info
Column D, Column E...
info info
for each element.
Instead of
Column A, B, C...
info info info info
in one row.
is there any way to do this with gridview? or i have to resign myself and do something similar with custom controls or Grids.
My listview
<ListView Background="Transparent"
x:Name="DatosEvento"
Margin="5"
MinWidth="{Binding ActualWidth, ElementName=Calendar}"
Width="Auto"
ItemsSource="{Binding Path=Eventos}"
Grid.Row="1"
Grid.Column="1">
<ListView.View>
<GridView>
<GridViewColumn Header="Organizador" DisplayMemberBinding="{Binding Path=Organizer.DisplayName}" />
<GridViewColumn Header="Correo Organizador">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Organizer.Email}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Nombre Evento" DisplayMemberBinding="{Binding Path=Summary}"/>
<GridViewColumn Header="Estado" DisplayMemberBinding="{Binding Path=Status}"/>
<GridViewColumn Header="Fecha Fin" DisplayMemberBinding="{Binding Path=End.Date}"/>
<GridViewColumn Header="Actualizado el" DisplayMemberBinding="{Binding Path=Updated.Date}"/>
<GridViewColumn Header="Enlace">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=HtmlLink}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
as i cant mark a comment as the solution, i have change the gridview for a mix of wrap and stackpanels, as #BionicCode suggested (he suggested the wrappanel i just added some stackpanels to do something similar to the gridview)

WPF How to set checkbox in Gridview binding in code behind

style that I have to create in code-behind. It has a checkbox that looks like this..
<GridView>
<GridViewColumn Width="30">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<CheckBox/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>-->
<GridViewColumn Header="Groups" DisplayMemberBinding="{Binding Groups}"/>
<GridViewColumn Header="SiteTitle" DisplayMemberBinding="{Binding SiteTitle}"/>
<GridViewColumn Header="SiteUrl" DisplayMemberBinding="{Binding SiteUrl}"/>
</GridView>
How I do in code-behind?
Just add this style in Resources and give it a x:Name.Let's assume the given name is CustomCheckboxTemplate , then a sample code will look like :
DynamicallyCreatedCheckbox.Style = (Style)FindResource("CustomCheckboxTemplate");
Hope this helps :)

How I can perform write operation on cell of list view in wpf

I am developing wpf application using C# without using any framework.until now i successfully performed following task on list view .
Displaying data in list view by binding with database table
Getting the selected row data from list view based on primary key
Now I am searching on google for creating and Editing cells of list view and found many links on winform list view editing.The link that i found on google on wpf but it is using framework.
http://tech.pro/tutorial/857/wpf-tutorial-using-the-listview-part-3-in-place-edit
Here is my list view .
<ListView x:Name="lvitems" HorizontalAlignment="Left" Height="180" Margin="681,286,0,0" ItemsSource="{Binding Path=Items}" VerticalAlignment="Top" Width="277">
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="S\No" DisplayMemberBinding="{Binding Path=id}" />
<GridViewColumn Width="50" Header="Code" DisplayMemberBinding="{Binding Path=Code}" />
<GridViewColumn Width="70" Header="Description" DisplayMemberBinding="{Binding Path=Description}" />
<GridViewColumn Width="50" Header="Rate" DisplayMemberBinding="{Binding Path=Rate}" />
<GridViewColumn Width="50" Header="Empty" DisplayMemberBinding="{Binding Path=Bottles}" />
</GridView>
</ListView.View>
</ListView>
Can some body tell me how to create and Edit the list view rows without using any framework ?Thanks

How to bind a ListView to an ObservableCollection<KeyValuePair<int,object>> inside a ViewModel in WPF?

Something like this:
public class EffectViewModel
{
public string Name ...
ObservableCollection<KeyValuePair<int,object>> settings
public ObservableCollection<KeyValuePair<int,object>> Settings
{
get {return this.settings;}
set
{
this.settings = value;
this.RaisePropertyChanged ( "Settings" );
}
}
}
Right now I am trying to bind it like this:
EffectWindowViewModel.Effects is of type ObservableCollection<EffectViewModel>.
<ListView Width="1000"
Height="600"
ItemsSource="{Binding EffectWindowViewModel.Effects}">
<ListView.View>
<GridView>
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Key}"
Header="Name" />
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Value}"
Header="Value" />
</GridView>
</ListView.View>
</ListView>
But I don't know how to specify .Settings property.
Any ideas?
your actual binding will not work cause EffectViewModel has no key and Value Property. i really dont know what your listview should display. if you want a list of EffectViewModels then the Itemssource is right. if you want further for each EffectViewModel to display the settings. then you need somekind of itemsscontrol with Itemssource={Binding Settings}. this itemsscontrol of course will need a itemsstemplate with your Key and Value.
i have no VS here atm, but your GridViewColumn needs a kind of CellTemplate. and this template should consist of a itemscontrol. because you have 2collections!
this code is probably not right but should take you in the right direction
<ListView Width="1000"
Height="600"
ItemsSource="{Binding EffectWindowViewModel.Effects}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Settings}">
<GridViewColumn.CellTemplate>
<DataTemplatex:Key="myCell4Settings">
<ListView ItemsSource="{Binding.}">
<ListView.View>
<GridView>
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Key}"
Header="Name" />
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Value}"
Header="Value" />
</GridView>
</ListView.View>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</ListView>
</DataTemplate>
</GridView>
</ListView.View>
btw you could also use 2 lists independent. one parent Combobox or listbox (x:Name=parent) with itemssource=EffectWindowViewModel.Effects and a second ListView like you have, with the itemssource binding:
ItemsSource="{Binding ElementName=parent, Path=SelectedItem.Settings}"
You could try:
ItemsSource="{Binding ElementName=Settings, Path=EffectWindowViewModel.Effects}"

How to display treeview inside listview in xaml + C# and MVP

How to display treeview inside a list view, actually this listview has headers namely workbook, description,date, so when I display the tree view inside the listview, the treeview should open as per the listview headers.
My question is :
1. How to insert treeview inside Listview and my xaml code is
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView Name="lstViewWorkbooks" HorizontalAlignment="Left" >
<ListView.View >
<GridView >
<GridViewColumn Header="WorkBook" Width="200" DisplayMemberBinding="{Binding AnyWorkbook}" />
<GridViewColumn Header="Description" Width="660" DisplayMemberBinding="{Binding DescName}" />
<GridViewColumn Header="Date" Width="183" DisplayMemberBinding="{Binding WorkbookDate}" />
</GridView>
</ListView.View>
<TreeView HorizontalAlignment="Left" Margin="195,76,0,-76" Name="tviewPojectView" Width="120" />
</ListView>
</ScrollViewer>
I am using MVP architecture, with C# and wpf.
The treeview in the above xaml code is enough to display the data?
Please help me
Thanks
Ramm
If you want the tree view inside a cell in your grid, you need to place it inside the cell template for the correct column like this:
<GridViewColumn Header="WorkBook" Width="200" DisplayMemberBinding="{Binding AnyWorkbook}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TreeView HorizontalAlignment="Left" Margin="195,76,0,-76" Name="tviewPojectView" Width="120" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

Categories

Resources