I have trouble with Listview I really do not know what to do. I create GridView inside ListView and now I have to ajust data in listview,
What I have to do is write new data information in existing row
New data have be in the same row, the color have to be different and new data have to be undern old data. Old data does not change, only 2 column and 4 column data crossed
My Xaml:
<ListView x:Name="lbPersonList" Margin="30,98.4,362,150" ScrollViewer.VerticalScrollBarVisibility="Visible"
AlternationCount="2" >
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumnHeader Content="Product">
</GridViewColumnHeader>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" FontSize="18px" FontFamily="Arial"
FontWeight="Normal" Width="670" TextAlignment="Left"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn >
<GridViewColumnHeader Content="Unit price, €"
HorizontalAlignment="Right">
</GridViewColumnHeader>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Age}" FontSize="18px" FontFamily="Arial"
FontWeight="Normal" Width="100" TextAlignment="Right"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn >
<GridViewColumnHeader Content="Quantity"
HorizontalAlignment="Center">
</GridViewColumnHeader>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Country}" FontSize="18px" FontFamily="Arial"
FontWeight="Normal" Width="130" TextAlignment="Center"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn >
<GridViewColumnHeader Content="Price, €"
HorizontalAlignment="Right">
</GridViewColumnHeader>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding adress}" FontSize="18px" FontFamily="Arial"
FontWeight="Bold" Width="100" TextAlignment="Right"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
.cs code:
public class Person
{
public string Name { get; set; }
public double Age { get; set; }
public string Country { get; set; }
public double adress { get; set; }
// public bool IsDiscount { get; set; }
// public string discounText { get; set; }
// public double discount { get; set; }
}
public partial class MainWindow : Window
{
ObservableCollection<Person> myList;
public MainWindow()
{
InitializeComponent();
myList = new ObservableCollection<Person>()
{
new Person{ Name="Name 1", Age=234444, Country="India", adress=1.01},
new Person{ Name="Name 2", Age=24, Country="India1", adress=12.45},
new Person{ Name="Name 3", Age=25, Country="India2", adress=45.84},
new Person{ Name="Name 4", Age=26, Country="India3", adress=12},
new Person{ Name="Name 5", Age=27, Country="India4", adress=41.21},
new Person{ Name="Name 6", Age=28, Country="India5", adress=15},
new Person{ Name="Name 7", Age=29, Country="India6", adress=8},
new Person{ Name="Name 8", Age=30, Country="India7", adress=9.11},
new Person{ Name="Name 9", Age=31, Country="India8", adress=7.99},
new Person{ Name="Name 10", Age=32, Country="India9", adress=18},
new Person{ Name="Name 11", Age=33, Country="India10", adress=74},
new Person{ Name="Name 12", Age=34, Country="India11", adress=78.21},
new Person{ Name="Name 13", Age=35, Country="India12", adress=101.01},
new Person{ Name="Name 14", Age=36, Country="India13", adress=7},
new Person{ Name="Name 15", Age=37, Country="India14", adress=9},
new Person{ Name="Name 16", Age=38, Country="India15", adress=12.15},
new Person{ Name="Name 17", Age=39, Country="India16", adress=0.14},
new Person{ Name="Name 18", Age=40, Country="India17", adress=0.99},
new Person{ Name="Name 19", Age=41, Country="India18", adress=98},
new Person{ Name="Name 20", Age=42, Country="India19", adress=47},
new Person{ Name="Name 21", Age=43, Country="India21", adress=1.99},
new Person{ Name="Name 22", Age=44, Country="India21", adress=1.90},
};
lbPersonList.ItemsSource = myList;
}
}
===============================================
EDIT: I get what I Want:
<GridViewColumn>
<GridViewColumnHeader Content="Product">
</GridViewColumnHeader>
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Grid>
<TextBlock Text="{Binding odd}" FontSize="18px" FontFamily="Arial"
FontWeight="Normal" Width="670" TextAlignment="Left"/>
</Grid>
<TextBlock Foreground="#B30C0C" FontFamily="Arial" FontWeight="Normal" FontSize="18px" Text="{Binding discounText}" Visibility="{Binding IsDiscount, Converter={StaticResource VisibilityConverter}}" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn >
List<MyData> sampleData = new List<MyData>
{
new MyData{odd="Name 1", unitPrice=455.45, quantity ="India1", Price=41.25,
IsDiscount=false, discounText="Surname 1", discountUnit=186, discountPrice=1.01},
new MyData{odd="Name 2", unitPrice=41.87, quantity ="India2", Price=47.56,
IsDiscount=false, discounText="Surname 2", discountUnit=84, discountPrice=12.45},
new MyData{odd="Name 3", unitPrice=234, quantity ="India3", Price=1.01,
IsDiscount=false, discounText="Surname 3", discountUnit=2744, discountPrice=45.84},
new MyData{odd="Name 4", unitPrice=2.45, quantity ="India4", Price=1.04,
IsDiscount=false, discounText="Surname 4", discountUnit=852, discountPrice=12},...
Also I use public class VisibilityConverter : IValueConverter
I'm not going to write the thing for you, but it seems pretty straight forward
<StackPanel Orientation="Vertical">
<Grid>
<TextBlock Text="{Binding Row1} VerticalAlignment="Center" />
<Rectangle Height="1" Fill="Red" VerticalAlignment="Center" Visibility={Binding Row2Visibility} />
</Grid>
<TextBlock Foreground="Red" Text="{Binding Row2} Visibility={Binding Row2Visibility} />
</StackPanel>
That's like a 5 second mock up of what I'd do :). Vertical stack panel contains the first row and the second row of text. The 2nd row of text has a visibility tied to it... the 1st row, I put it inside of a grid so its easy to do the strike through line. If you want to do the strike through the "right" way, that would entail cloning the system font and adding the strike through... when really the strike through is just a line, so no biggie. The strike through line visibility is the same visibility as the 2nd row of text obviously. They are either both visible or both collapsed.