xaml에 DateTemplate를 이용 해 리스트뷰 아이템 추가 시 자동으로 버튼도 추가된다..
//Xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListView x:Name="listView1" HorizontalAlignment="Left" Height="338" Margin="0,0,-5,-18" VerticalAlignment="Top" Width="522">
<ListView.View>
<GridView>
<GridViewColumn Width="80" Header="선 택">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="선 택" Height="25" Width="60" HorizontalAlignment="Center" Click="Button_Click"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="80" Header="강의코드" DisplayMemberBinding="{Binding Memo}"/>
<GridViewColumn Width="100" Header="강의명" DisplayMemberBinding="{Binding Subject}"/>
<GridViewColumn Width="80" Header="강의실" DisplayMemberBinding="{Binding Class}"/>
<GridViewColumn Width="80" Header="교 수" DisplayMemberBinding="{Binding Professor}"/>
<GridViewColumn Width="100" Header="강의시간" DisplayMemberBinding="{Binding ScheDule}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
//Xaml.cs
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
listView1.Items.Add(new CustomerInfo() { Memo ="1", Subject = "2", Class = "3", Professor = "4", ScheDule = "5" });
}
//리스트뷰에서 선택한 항목의 정보를 얻어온다.
private static CustomerInfo ListView_GetItem(RoutedEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
while (!(dep is System.Windows.Controls.ListViewItem))
{
try
{
dep = VisualTreeHelper.GetParent(dep);
}
catch
{
return null;
}
}
ListViewItem item = (ListViewItem)dep;
CustomerInfo content = (CustomerInfo)item.Content;
return content;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CustomerInfo info = ListView_GetItem(e);
}
}
public class CustomerInfo
{
private string _Memo;
private string _Subject;
private string _Class;
private string _Professor;
private string _ScheDule;
public string Memo { get { return _Memo; } set { _Memo = value; } }
public string Subject { get { return _Subject; } set { _Subject = value; } }
public string Class { get { return _Class; } set { _Class = value; } }
public string Professor { get { return _Professor; } set { _Professor = value; } }
public string ScheDule { get { return _ScheDule; } set { _ScheDule = value; } }
}
}
'프로그래밍언어 > C#' 카테고리의 다른 글
xamarin 값 저장 (0) | 2014.08.24 |
---|---|
C# 소켓통신 (0) | 2014.06.16 |
thread (0) | 2014.06.10 |
thread.invoke (0) | 2014.06.10 |
스레드 파라미터넘기기 (0) | 2014.06.10 |