Additional column in GridView - wpf

I use a List to populate a WPF GridView as its ItemsSource. This is the xaml markup I use:
<ListView.View>
<GridView>
<GridViewColumn Header="Subject" DisplayMemberBinding="{Binding Path=Subject}" />
<GridViewColumn Header="Start" DisplayMemberBinding="{Binding Path=StartingDate}" />
<GridViewColumn Header="End" DisplayMemberBinding="{Binding Path=EndingDate}" />
<GridViewColumn Header="Commissioner" DisplayMemberBinding="{Binding Path=Commissioner}" />
<GridViewColumn Header="Description" DisplayMemberBinding="{Binding Path=QuickNotes}" />
</GridView>
</ListView.View>
Surprisingly (at least for me), I get an additional (empty) column as shown below. What important point am I missing?

One alternative is to use a DataGrid instead of the ListView. Then you can set one of the Columns to have a Width of * which will cause it to take up all remaining space. Sadly you can't set a width of * on GridView columns.
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Header="Subject" />
<DataGridTextColumn Header="Start" />
<DataGridTextColumn Header="End" />
<DataGridTextColumn Header="Commissioner" />
<DataGridTextColumn Header="Description" Width="*" />
</DataGrid.Columns>
</DataGrid>

It's not an "actual" column, it's more like empty space next to the last column.

Related

How to bind double click on row to command in GridView that inside ListView in MVVM WPF

I'm prrety new to wpf, and i try to make a GridView that inside ListView to response to double click on row in the view
I try to make this-
<ListView
ItemsSource="{Binding Products}">
<ListView.InputBindings>
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding Test}" />
</ListView.InputBindings>
<ListView.View>
<GridView>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn
Header="ID"
DisplayMemberBinding="{Binding ID}" />
<GridViewColumn
Header="Name"
DisplayMemberBinding="{Binding Name}" />
<GridViewColumn
Header="Category"
DisplayMemberBinding="{Binding Category}" />
<GridViewColumn
Header="Price"
DisplayMemberBinding="{Binding Price}" />
</GridView>
</ListView.View>
<ListView />
when Test is an ICommand property in the view model.
But it's not responding to double click.
What am I getting wrong, and mabye there is another way?

WPF: When Adding items to a listview they become empty

Im a bit new to WPF and I cant seem to figure out why the items I add to a listview are displaying empty.
Here is my XAML
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="30" DisplayMemberBinding="{Binding Source={StaticResource BillingIncrements}, Path=ID}" />
<GridViewColumn Header="Bill Group" DisplayMemberBinding="{Binding Source={StaticResource BillingIncrements}, Path=Description}" />
</GridView>
</ListView.View>
Here is the code
lstBillGroups.Items.Add(New StlReportPlugins.BillingIncrements With {.ID = 100, .Description = "Test"})
Here is the output
(couldnt post a pic because i dont have enough points)
Link to pic
Any Ideas?
This is how your XAML should look like
<ListView ItemsSource={Binding Source={StaticResource BillingIncrements}}>
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="30" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="Bill Group" DisplayMemberBinding="{Binding Description}"/>
</GridView>
</ListView.View>
</ListView>
If you have a look at output window in VS while debugging your app you'll see a bunch of WPF binding errors, which helps a lot to spot mistakes.

Add an empty column in WPF GridView

I have a ListView (GridView) bound to a collection. For aesthetic reason, I want an empty column at the beginning. If I do
<ListView.View>
<GridView>
<GridViewColumn Width="100" />
<GridViewColumn Header="Col 1" DisplayMemberBinding="{Binding P1}" />
<GridViewColumn Header="Col 2" DisplayMemberBinding="{Binding P2}" />
<GridViewColumn Header="Col 3" DisplayMemberBinding="{Binding P3}" />
</GridView>
</ListView.View>
I get the .ToString() of the ItemSource in the first column. I just want an empty column, and I do not want to bind to an empty string property. Any idea?
I just hope it is not too obvious...
Maybe use an empty CellTemplate?
<GridViewColumn Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate />
</GridViewColumn.CellTemplate>
</GridViewColumn>
Or just don't specify anything...
<GridViewColumn Header="Col 3" Width="500" />

how to Style gridview rows during runtime in wpf?

<ListView.View>
<GridView>
<GridViewColumn Header="اسم الشركة" DisplayMemberBinding="{Binding Path=company_name}" Width="200" />
<GridViewColumn Header="رمز الشركة" DisplayMemberBinding="{Binding Path=symbol}" Width="Auto" />
<GridViewColumn Header="سعر السهم" DisplayMemberBinding="{Binding Path=price}" Width="Auto" />
<GridViewColumn Header="نسبة التغير" DisplayMemberBinding="{Binding Path=change_percent}" Width="Auto" />
</GridView>
</ListView.View>
I have the previous XAML tags to define the listview I am using in my wpf - C# application
I want to give each row in my listview a specific color that would be chosen during runtime
I know it might be a silly question but I need it badly and I have looked for it alot with no results
Can you help me ?
Is this something you are looking for?

To change gridview cell font size in WPF

I have a GridView in a Listview.View in a WPF application. I am using sorting of each grid view column so I need to set display member binding. When I searched in net I got a method using cell template to increase the font size of elements in the grid view. But I cannot use that since I need DisplayMemberBinding property of gridview for sorting. Any other method to increase the FontSize of the elements in GridView?
I realize this is an older post, but just in case someone was looking for an answer to the same question...
You should be able to simply set the Width property. This is pulled straight from a project I'm working on:
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="Id" DisplayMemberBinding="{Binding Id}" />
<GridViewColumn Width="135" Header="First Name" DisplayMemberBinding="{Binding FirstName}" />
<GridViewColumn Width="165" Header="Last Name" DisplayMemberBinding="{Binding LastName}" />
<GridViewColumn Width="100" Header="Passcode" DisplayMemberBinding="{Binding Passcode}" />
<GridViewColumn Width="125" Header="Type" DisplayMemberBinding="{Binding AccountType}" />
</GridView>
</ListView.View>
This works just fine for me.

Resources