XAML:
<!-- HEADER-->
<StackPanel Orientation="Horizontal" >
<TextBlock Width="250" TextAlignment="Center" Text="User"/>
<TextBlock Width="250" TextAlignment="Center" Text="Details"/>
<TextBlock Width="100" TextAlignment="Center" Text="Action"/>
</StackPanel>
<!--ListView-->
<ListView x:Name="lb_Users">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="600">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Details}" />
<Button Tag="{Binding}" Click="ActionButtonClick"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
C#
構造体を定義します:
struct User
{
public string Name { get; set; }
public string Details { get; set; }
}
リストボックスのロード:
public void ShowList()
{
List<User>Users=new List<User>();
//Here we have to fill this list by some data.
lb_Users.ItemSource=Users;
}
ボタン アクティビティ:
private void ActionButtonClick(object sender, RoutedEventArgs e)
{
Button btn=sender as Button;
User user=(User)Button.Tag; //we gets our user
// do something else...
}