Then, unfortunately, you're not really using WPF. (opinion).
If you use DataView as ItemsSource the SelectedItem will be a DataRowView.
<Window x:Class="MSDNTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
Width="640" Height="480">
<StackPanel>
<dg:DataGrid x:Name="dataGrid" SelectionMode="Single"/>
<TextBox x:Name="property" Text="Age"/>
<TextBlock x:Name="result"/>
</StackPanel>
</Window>
using System;
using System.Data;
using System.Windows;
namespace MSDNTest
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
var table = new DataTable();
var colname = new DataColumn("Name", typeof(string));
table.Columns.Add(colname);
var colage = new DataColumn("Age", typeof(int));
table.Columns.Add(colage);
for (var i = 0; i < 10; i++)
{
var row = table.NewRow();
row["Name"] = "Name " + (i + 1);
row["Age"] = 20 + i;
table.Rows.Add(row);
}
dataGrid.ItemsSource = table.DefaultView;
dataGrid.SelectionChanged += (s, e) =>
{
var item = dataGrid.SelectedItem as DataRowView;
if (null == item) return;
try
{
result.Text = item.Row[property.Text].ToString();
}
catch (Exception ex)
{
result.Text = ex.Message;
}
};
}
}
}
Bigsby, Lisboa, Portugal -
O que for, quando for, é que será o que é...
http://bigsby.eu