<ResourceDictionary x:Class="ListViewCustomControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfCustomControlLibrary2"> <Style TargetType="{x:Type local:ListViewCustomControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:ListViewCustomControl}"> <Border removed="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <ListView x:Name="ListView1" ItemsSource="{Binding ObjData}" Width="600"> <ListView.View> <GridView> <GridViewColumn Header="Subject" DisplayMemberBinding="{Binding Subject}" Width="100"></GridViewColumn> <GridViewColumn Header="Due Date" DisplayMemberBinding="{Binding DueDate}" Width="100"></GridViewColumn> <GridViewColumn Header="Status" DisplayMemberBinding="{Binding Status}" Width="100"></GridViewColumn> <GridViewColumn Header="Priority" DisplayMemberBinding="{Binding Priority}" Width="100"></GridViewColumn> </GridView> </ListView.View> </ListView> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
public class ListViewCustomControl : ListView { static List<Record> ObjData = new List<Record>(); static ListViewCustomControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ListViewCustomControl), new FrameworkPropertyMetadata(typeof(ListViewCustomControl))); } public void GetData() { Sp_Activity_Task_BindGridTableAdapter SqlAdptr = new Sp_Activity_Task_BindGridTableAdapter(); foreach (DataRow Row in SqlAdptr.GetMeetings()) { ObjData.Add(new Record(Row["Subject"].ToString(), Row["DueDate"].ToString(), Row["Status"].ToString(), Row["Priority"].ToString())); } } public ListViewCustomControl() { GetData(); DataContext = ObjData; } } public class Record { private string _Subject; private string _DueDate; private string _Status; private string _Priority; public string Subject { get { return _Subject; } set { _Subject = value; } } public string DueDate { get { return _DueDate; } set { _DueDate = value; } } public string Status { get { return _Status; } set { _Status = value; } } public string Priority { get { return _Priority; } set { _Priority = value; } } public Record(string Subject,string DueDate,string Status,string Priority) { this._Subject = Subject; this._DueDate = DueDate; this._Status = Status; this._Priority = Priority; } }
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)