how to template a listview item / wpf - 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.

Related

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>

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?

WPF control ListView

In C# ListView -> ListItem -> subItem.
How to add a new entry to a list using WPF?
To add data such as ListView WF, you must use binding.
For example:
<ListView ItemsSource="{Binding}" x:Name="lv">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}"/>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
Show data of two column(ID, Name) with this example
Your question is hardly intelligible but let's just shoot into the blue:
Adding items in XAML:
<ListView>
<ListViewItem>
<!-- Item Content -->
</ListViewItem>
</ListView>
In code behind:
listView.Items.Add(new ListViewItem() { Content = content });
(ListViewItems do not have sub-items by the way)

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