how to Style gridview rows during runtime in wpf? - 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?

Related

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" />

Sorting the WPF Listview

Iam having a ListView named "ListLoginDetails" in WPF. In which I displays two columns namely "User_Name", "Password" through DataSet. Now I haven to Sort the ListView on Both Ascending & Descending Order. Based upon the button clicked.....
Home.Xaml:
<ListView Name="ListLoginDetails" ItemsSource="{Binding Path=Table}" Margin="18,0,0,0" Grid.RowSpan="3" >
<ListView.View>
<GridView x:Name="gridView">
<GridViewColumn Width="100" Header="User_Name" DisplayMemberBinding="{Binding Path=Id}" />
<GridViewColumn Width="140" Header="Password" DisplayMemberBinding="{Binding Path=Password}" />
</GridView>
</ListView.View>
</ListView>

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.

how to template a listview item / wpf

I am trying to achieve this using Expression Blend 3. I need that every listview item to contain an image, followed by a text. ItemTemplate doesn't seem to work.
Thanks
Listview is differnt then the List control. For ListView you have to add a "View" to the object, then define your columns.
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Column 1" />
<GridViewColumn Width="140" Header="Column 2" />
<GridViewColumn Width="140" Header="Column 3" />
</GridView>
</ListView.View>
</ListView>
you should check this tutorial.

Resources