how to access specific control in datatemplate generated listbox - c#

So i have dataTemplate generated listbox like this:
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Rectangle Fill="{Binding color}" Height="10" Width="10" Grid.Column="1"/>
<TextBlock Text=" " Grid.Column="2"/>
<TextBlock Text="{Binding ID}" FontSize="10" FontWeight="Bold" Grid.Column="3"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate
and I bind it to ObservableCollection. I need to access specific item in this listbox and change colour of its rectangle element.

I would use a StyleSelector. make a styleselector like this:
ListViewItemStyleSelector.cs
public class ListViewItemStyleSelector : StyleSelector
{
public override Style SelectStyle(object item,
DependencyObject container)
{
Style st = new Style();
st.TargetType = typeof(ListViewItem);
Setter backGroundSetter = new Setter();
backGroundSetter.Property = ListViewItem.BackgroundProperty;
ListView listView =
ItemsControl.ItemsControlFromItemContainer(container)
as ListView;
int index =
listView.ItemContainerGenerator.IndexFromContainer(container);
if (index % 2 == 0) <-- here your own criteria
{
backGroundSetter.Value = Brushes.LightBlue;
}
else
{
backGroundSetter.Value = Brushes.Beige;
}
st.Setters.Add(backGroundSetter);
return st;
}
}
use of the styleselector
xaml
<ListView
ItemsSource="{Binding Source={StaticResource EmployeeData},
XPath=Employee}"
ItemContainerStyleSelector="{DynamicResource myStyleSelector}" >
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding XPath=FirstName}"
Header="First Name" Width="120"/>
<GridViewColumn DisplayMemberBinding="{Binding XPath=LastName}"
Header="Last Name" Width="120"/>
<GridViewColumn DisplayMemberBinding="{Binding XPath=FavoriteCity}"
Header="Favorite City" Width="120"/>
</GridView>
</ListView.View>
</ListView>

Related

WPF Draw a line from a label to a selected item in a listbox

I am making a matching item user control.
On the left I have a Label that is bound to the value the user is trying to match.
On the right I have a ListVIew populated with possible matches for the value on the left.
After the user selects the match in the list I want to draw a line from the label to the selected ListView Item that will also update when the list is scrolled.
I don't know how to get positions and draw the line. Any ideas?
<Canvas Name="ConnectionCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" Background="Red">
<Grid Name="ConnectionGrid" Width="{Binding ActualWidth, ElementName=ConnectionCanvas}"
Height="{Binding ActualHeight, ElementName=ConnectionCanvas}">
<Label Name="SourceLabel" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding ValueToMatch}"/>
<ListView Name="DestinationList" Margin="5" Width="300" SelectionMode="Single"
HorizontalAlignment="Right" VerticalAlignment="Stretch"
ItemsSource="{Binding PossibleMatchLookupCollection}"
SelectedValuePath="Identifier" SelectedValue="{Binding Path=SelectedMatch}"
IsSynchronizedWithCurrentItem="True"
userControls:GridViewSort.AutoSort="True"
userControls:GridViewSort.SortGlyphAscending="pack://application:,,,/Divestco.Windows.Resources;component/PNGs/General/Small/UpArrow.png"
userControls:GridViewSort.SortGlyphDescending="pack://application:,,,/Divestco.Windows.Resources;component/PNGs/General/Small/DownArrow.png">
<i:Interaction.Behaviors>
<behaviors:ListViewGridViewColumnAutoWidthBehavior/>
</i:Interaction.Behaviors>
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridView.Columns>
<GridViewColumn Header="{Binding Path=FirstColumnDisplayName}" DisplayMemberBinding="{Binding Path=FirstColumnValue}" userControls:GridViewSort.PropertyName="FirstColumnValue" />
<GridViewColumn Header="{Binding Path=SecondColumnDisplayName}" DisplayMemberBinding="{Binding Path=SecondColumnValue}" userControls:GridViewSort.PropertyName="SecondColumnValue" />
<GridViewColumn Header="{Binding Path=ThirdColumnDisplayName}" DisplayMemberBinding="{Binding Path=ThirdColumnValue}" userControls:GridViewSort.PropertyName="ThirdColumnValue" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
<Line Name="ConnectorLine" Stroke="Black" />
</Grid>
</Canvas>
Code behind:
private void HandleSelectionChanged(object sender, SelectionChangedEventArgs e)
{
Point relativeLefttPoint = SourceLabel.TransformToAncestor(ConnectionGrid)
.Transform(new Point(0, 0));
UIElement selectedContainer = (UIElement)DestinationList.ItemContainerGenerator.ContainerFromIndex(DestinationList.SelectedIndex);
Point relativeRightPoint = default(Point);
if (selectedContainer != null)
{
relativeRightPoint =
selectedContainer.TranslatePoint(new Point(selectedContainer.DesiredSize.Width, 0.0), ConnectionGrid);
}
ConnectorLine.X1 = relativeLefttPoint.X;
ConnectorLine.X2 = relativeLefttPoint.Y;
ConnectorLine.Y1 = relativeRightPoint.X;
ConnectorLine.Y2 = relativeRightPoint.Y;
}

'ListViewItem' does not contain a contructor that takes 1 argument, Windows phone c#

Hi I am trying to add items to a listview but get the following error, 'ListViewItem' does not contain a constructor that takes 1 argument.
I am getting the error here new ListViewItem(row);
I am using Windows phone 8.1 in c#.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
int totalq = int.Parse(textBox.Text) + app.vanilla;
textBox.Text = totalq.ToString();
double totalvanilla = Convert.ToDouble(totalq)* 1.50;
textBox_Copy.Text = totalvanilla.ToString();
//listBox.Items.Add(totalq.ToString() + "Vanilla");
string[] row = { totalq.ToString(),"vanilla" };
var listViewItem = new ListViewItem(row);
listView.Items.Add(listViewItem);
}
I think you're the System.Windows.Forms.ListViewItem (which has a constructor for taking a string array) with the xaml-based System.Windows.Controls.ListViewItem.
You'd use the latter in another way:
XAML:
<ListView x:Name="listView">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
<GridViewColumn Header="Qunatity" DisplayMemberBinding="{Binding Path=Quantity}"/>
</GridView>
</ListView.View>
</ListView>
Code:
int totalq = 23;
var row = new { Quantity = totalq, Name = "vanilla" };
listView.Items.Add(row);
Edit:
If GridView isn't an option for you and you want to / have to put everything in place yourself, you can use following approach (based on this answer):
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Quantity}" />
<TextBlock Grid.Column="1" Text="{Binding Name}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You are sending string as parameters to listviewtem.ListViewItem has content property ,
Do like this
listView.Items.Add(new ListViewItem{Content = whateveryourstring});
I think you need to add a class with the property that you want to show at view.
Like this.
public class ListModel {
public string TotalQuantity { set; get; }
public string Name { set; get; }
}
Then try this XAML
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
<toolkit:ListView Name="listView">
<toolkit:ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding TotalQuantity}" />
<TextBlock Grid.Column="1" Text="{Binding Name}" />
</Grid>
</DataTemplate>
</toolkit:ListView.ItemTemplate>
</toolkit:ListView>
Finaly add the itemsource for list view
int totalq = int.Parse("3") + 2;
textBox.Text = totalq.ToString();
double totalvanilla = Convert.ToDouble(totalq) * 1.50;
textBox_Copy.Text = totalvanilla.ToString();
listBox.Items.Add(totalq.ToString() + "Vanilla");
ListViewItems = new ObservableCollection<ListModel>();
ListViewItems.Add(new ListModel()
{
TotalQuantity = totalq.ToString(),
Name = "vanilla"
});
listView.ItemsSource = ListViewItems;

WPF ListView group and sort

I'm trying to group items on my list and sort them from oldest to newest. Grouping works perfect, it just doesn't want to inverse this list.
WPF Code:
<ListView x:Name="lst_orders" Margin="5" GridViewColumnHeader.Click="results_Click">
<ListView.Resources>
<Style TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="true">
<Setter Property="IsSelected" Value="true" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="goto_parts" Content="Show parts" Width="AUTO" Padding="2" Margin="2" Background="#FF179917" Click="goto_parts_Click"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Order ID" Width="100" DisplayMemberBinding="{Binding fullOrderId}" />
<GridViewColumn Header="Job Status" Width="100" DisplayMemberBinding="{Binding status}" />
<GridViewColumn Header="Order Type" Width="150" DisplayMemberBinding="{Binding orderType}" />
<GridViewColumn Header="Customer Notes" Width="250" DisplayMemberBinding="{Binding notes}" />
<GridViewColumn Header="Admin Notes" Width="250" DisplayMemberBinding="{Binding adminNotes}" />
<GridViewColumn Header="Production Notes" Width="100" DisplayMemberBinding="{Binding production_notes}" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="Gray">
<TextBlock Text="Days: " FontSize="18" FontWeight="Bold"/>
<TextBlock Text="{Binding Name}" FontSize="18" FontWeight="Bold"/>
<TextBlock Text=" Systems: " FontSize="18" FontWeight="Bold"/>
<TextBlock Text="{Binding ItemCount}" FontSize="18" FontWeight="Bold"/>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
C# Code:
ICollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lst_orders.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("daysOld");
view.GroupDescriptions.Add(groupDescription);
view.SortDescriptions.Add(new SortDescription("daysOld", ListSortDirection.Descending));
lst_orders.ItemsSource = view;
daysOld is a property that calculates difference between today's date and order date, works perfect, but I want to see it from the highest number to the lowest. Picture shows what I get, and I want to reverse it.
Your code is correct.I've made a test. It is possible to see in view:
C#:
List<SomeClass> list = new List<SomeClass>();
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
list.Add(new SomeClass() { DaysOld = DateTime.Now.Add(new TimeSpan(0, rnd.Next(25), 0))});
}
ICollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(list);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("daysOld");
view.GroupDescriptions.Add(groupDescription);
view.SortDescriptions.Add(new SortDescription("DaysOld", ListSortDirection.Descending));
listBox.ItemsSource = view;
listBox.DisplayMemberPath = "DaysOld";
XAML:
<ListBox Name="listBox"/>
Model:
public class SomeClass
{
public DateTime DaysOld { get; set; }
}
Image:

ComboBox in WPF Datagrid c#

I have a DataGrid and fill it with a DataTable.
dgMitarbeiter.ItemsSource = mainController.loadDataTableMitarbeiter().DefaultView;
this is the function:
public DataTable loadDataTableMitarbeiter()
{
loadMitarbeiterList();
dtMitarbeiter.Clear();
foreach (Mitarbeiter mitarbeiter in mitarbeiterList)
{
drMitarbeiter = dtMitarbeiter.NewRow();
drMitarbeiter["ID"] = mitarbeiter.ID;
drMitarbeiter["Vorname"] = mitarbeiter.vorname;
drMitarbeiter["Nachname"] = mitarbeiter.nachname;
drMitarbeiter["Kostenstelle"] = mitarbeiter.kostenstelle.id;
drMitarbeiter["Größe Hose"] = mitarbeiter.gr_hose;
drMitarbeiter["Größe Oberteil"] = mitarbeiter.gr_oberteil;
drMitarbeiter["Gröse Schuhe"] = mitarbeiter.gr_schuhe;
drMitarbeiter["Ferial"] = mitarbeiter.ferial;
drMitarbeiter["Werk"] = mitarbeiter.werk;
drMitarbeiter["Datum"] = mitarbeiter.creationDate.ToString("dd.MM.yyyy");
dtMitarbeiter.Rows.Add(drMitarbeiter);
}
return dtMitarbeiter;
}
The Xaml:
<DataGrid x:Name="dgMitarbeiter" AlternatingRowBackground="Gainsboro" AlternationCount="2" ColumnWidth="*" HorizontalAlignment="Left" SelectedItem="{Binding SelectedItem}" Margin="10,22,0,0" VerticalAlignment="Top" Height="357" Width="731" CanUserAddRows="False" CanUserDeleteRows="False" RowEditEnding="dgMitarbeiter_RowEditEnding" Background="White" HeadersVisibility="Column"/>
I need a ComboBox for the column "Kostenstelle" but have no idea how to achieve this. Any ideas?
My answer implements an ObservableCollection. And adds this as a databinding to the ComboBox
You need a new class:
public class Kostenstellen: ObservableCollection<Kostenstelle>
{
}
And a fill Method with the following lines of code:
var kostenstellen = new Kostenstellen();
foreach mitarbeiter in mitarbeiterList
{
kostenstellen.Add(mitarbeiter.kostenstelle);
}
var cvsCombobox = new CollectionViewSource() { Source = this.operationList };
this.myCombobox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding() { Source = cvsCombobox });
Now there will be only "(Kostenstelle)" as a string in the Combobox.
So you need to override the ToString() method of your Kostenstelle class
public partial class Kostenstelle
{
public override string ToString()
{
return this.ID.ToString();
}
}
HINT:
Use english variable and class names next time :)
You need to define a DataGridComboBoxColumn in your DataGrid columns, you can then bind the ItemsSource to wherever your combo box's options are located.
See here.
You can do a lot in your xaml file :) For myself I used this one lately...
In the xaml file you can now define the placement of the combobox on your page.
you can set the content by code later.
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Items In Group"
TabIndex="1"
Grid.RowSpan="2"
Padding="120,126,120,50"
ItemsSource="{Binding}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick"
>
<GridView.ItemTemplate >
<DataTemplate >
<Grid Height="150" Width="480" Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,10,0,0" >
<TextBlock Text="{Binding title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" FontSize="25"/>
<Line/>
<TextBlock Text="{Binding subtitle}" Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="NoWrap" FontSize="20" Margin="0,10,0,0" />
<Line/>
<TextBlock Text="{Binding description}" Style="{StaticResource BodyTextBlockStyle}" MaxHeight="60" FontSize="15" Margin="0,10,0,0"/>
<Button Tag="{Binding title}" Click="ItemButtonClicked" Content="Details" FontSize="15" Margin="0,10,0,0"/>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemContainerStyle>
<Style TargetType="FrameworkElement" >
<Setter Property="Margin" Value="52,0,0,2"/>
</Style>
</GridView.ItemContainerStyle>
</GridView>

Show data from textboxes into listview in wpf

I have a C# project have :
The XAML Code:
<Window x:Class="Revision.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Patient Information" Height="456.36" Width="935.208">
<Window.Resources>
<Style x:Key="SliderStyle">
<Setter Property="FrameworkElement.Width" Value="100"/>
<Setter Property="RangeBase.Minimum" Value="0"/>
<Setter Property="RangeBase.Maximum" Value="100"/>
<Setter Property="Slider.IsSnapToTickEnabled" Value="true"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="RangeBase.Value" Value="0"/>
<Setter Property="Slider.AutoToolTipPlacement" Value="TopLeft"/>
</Style>
</Window.Resources>
<Grid>
<Label Content="First Name" Height="28" HorizontalAlignment="Left" Margin="19,23,0,0" Name="label1" VerticalAlignment="Top" />
<Label Content="Last Name" Height="28" HorizontalAlignment="Left" Margin="19,82,0,0" Name="label2" VerticalAlignment="Top" />
<Label Content="Address" Height="28" HorizontalAlignment="Left" Margin="20,144,0,0" Name="label3" VerticalAlignment="Top" />
<Label Content="Security Type" Height="28" HorizontalAlignment="Left" Margin="19,203,0,0" Name="label4" VerticalAlignment="Top" />
<TextBox Height="36" HorizontalAlignment="Left" Margin="105,23,0,0" Name="textBox1" VerticalAlignment="Top" Width="197" />
<TextBox Height="36" HorizontalAlignment="Left" Margin="105,82,0,0" Name="textBox2" VerticalAlignment="Top" Width="197" />
<TextBox Height="36" HorizontalAlignment="Left" Margin="105,136,0,0" Name="textBox3" VerticalAlignment="Top" Width="197" />
<ComboBox Height="36" Margin="105,195,625,0" Name="comboBox1" VerticalAlignment="Top">
<ComboBoxItem Content="Private Assurance" Name="PrA"/>
<ComboBoxItem Content="Public Assurance" Name="PA"/>
<ComboBoxItem Content="No Assurance" Name="NA"/>
</ComboBox>
<Button Content="Submit" Height="33" HorizontalAlignment="Left" Margin="147,365,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click"/>
<Button Content="Display" Height="33" HorizontalAlignment="Left" Margin="227,365,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
<Label Content="Gender" HorizontalAlignment="Left" Margin="20,255,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="maleRadio" Content="Male" HorizontalAlignment="Left" Margin="105,266,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="femaleRadio" Content="Female" HorizontalAlignment="Left" Margin="192,266,0,0" VerticalAlignment="Top"/>
<Slider x:Name="redSlider" Style="{StaticResource SliderStyle}" Value="{Binding Text, ElementName=textBox5}" Margin="74,313,636,56" SmallChange="1" Height="56" Width="Auto" />
<TextBox x:Name="textBox5" Text="{Binding Value, ElementName=redSlider}" Margin="296,313,588,86" SelectionOpacity="1" FontSize="13" />
<Label Content="Age" HorizontalAlignment="Left" Margin="38,313,0,0" VerticalAlignment="Top"/>
<ListView x:Name="ListView1" HorizontalAlignment="Left" Height="375" Margin="344,23,0,0" VerticalAlignment="Top" Width="567">
<ListView.View>
<GridView>
<GridViewColumn Header="First Name" Width="100"
DisplayMemberBinding="" />
<GridViewColumn Header="Last Name" Width="80"
DisplayMemberBinding="" />
<GridViewColumn Header="Address" Width="100"
DisplayMemberBinding="" />
<GridViewColumn Header="Security Type" Width="80"
DisplayMemberBinding="" />
<GridViewColumn Header="Gender" Width="100"
DisplayMemberBinding="" />
<GridViewColumn Header="Age" Width="100"
DisplayMemberBinding="" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
and I have a class patient:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Revision
{
class Patient
{
public string firstname { get; set; }
public string lastname { get; set; }
public string Address { get; set; }
public string securityType {get; set;}
public string gender { get; set; }
public string age { get; set; }
public Patient(string fn, string ln, string ad, string st,string ge,string ag)
{
firstname = fn;
lastname = ln;
Address = ad;
securityType = st;
gender = ge;
age = ag;
}
public override string ToString()
{
return string.Format("{0,-10} {1,-10} {2,-10} {3,-10} {4,-10} {5,-10}",
firstname, lastname, Address, securityType, gender,age);
}
}
}
and the main program
public partial class MainWindow : Window
{
// Patient [] patients = new Patient{}
Patient [] patients = new Patient[100];
private List<Patient> books = new List<Patient>();
int i=0;
string g;
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string x = "";
if (PrA.IsSelected)
{
x = PrA.Content.ToString();
}
else if (PA.IsSelected)
{
x = PA.Content.ToString();
}
else if (NA.IsSelected)
{
x = NA.Content.ToString();
}
if (maleRadio.IsChecked == true)
g = "Male";
if(femaleRadio.IsChecked==true)
g="Female";
patients[i] = new Patient(
textBox1.Text, textBox2.Text, textBox3.Text, g, textBox5.Text, x);
i = i + 1;
// Patient[] patients = {
// new Patient (
// textBox1.Text, textBox2.Text, textBox3.Text, x)};
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox5.Clear();
}
}
So the question I want to display the data entered in the textboxes,radio button and combo box... in the List view
The normal way of getting your data into the listview would be through databinding. Databinding is the way that WPF uses to transport data between your view and your code.
All wpf controls that can show multiple items, like listview, listbox, combobox etc, has a ItemSource property. By setting this property to an enumerable, the view will display each item in the collection.
By default, it will just render each item as a textblock showing the result of calling ToString() on each object. There are several ways of customizing this. In your case, you have defined columns with a GridView and GridViewColumns. Each GridViewColumn has a DisplayMemberBinding which can be binded to the property you want to display in that column.
So...
I'm not sure how easy it will be for you to use this. As mentioned by others, you really should learn a little bit about binding in wpf, and the Model-View-ViewModel (MVVM) pattern. MVVM really helps keeping the code clean.
Anyways...
Your view could be changed to something like this:
<ListView x:Name="ListView1" HorizontalAlignment="Left" Height="375" Margin="344,23,0,0" VerticalAlignment="Top" Width="567" ItemsSource="{Binding patients}">
<ListView.View>
<GridView>
<GridViewColumn Header="First Name" Width="100" DisplayMemberBinding="{Binding path=firstname}" />
<GridViewColumn Header="Last Name" Width="80" DisplayMemberBinding="{Binding path=lastname}" />
<GridViewColumn Header="Address" Width="100" DisplayMemberBinding="{Binding path=Address}" />
<GridViewColumn Header="Security Type" Width="80" DisplayMemberBinding="{Binding path=securityType}" />
<GridViewColumn Header="Gender" Width="100" DisplayMemberBinding="{Binding path=gender}" />
<GridViewColumn Header="Age" Width="100" DisplayMemberBinding="{Binding path=age}" />
</GridView>
</ListView.View>
</ListView>
I would change your fixed size array of patients to a ObservableCollection<Patient>. A collection that can grow in size is almost always better than a fixed size one. The ObservableCollection<> has some extra tricks as well. It will notify the view whenever items are added or removed.
Take a look at wpftutorial.net. You will find a nice introduction to binding , MVVM and a lot more.

Categories

Resources