Combobox Item selecionado WPF c #
Quero obter o item selecionado na caixa de combinação wpf. Mas ele retorna System.Data.DataRowView. Meu código em xaml:
<ComboBox Name="ddDeputi" Margin="131,85,0,0" Width="327" HorizontalAlignment="Left" VerticalAlignment="Top" Height="22"
SelectedValue="{Binding Path = kodeDep, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Validation.ErrorTemplate="{x:Null}" SelectionChanged="ddDeputi_SelectionChanged" Loaded="ddDeputi_Loaded" />
E no meu .cs:
private void ddDeputi_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ddDeputi.SelectedIndex != -1)
{
string akode = ddDeputi.SelectedValue.ToString();
DaUnitKerja oDa = new DaUnitKerja();
DataSet data = new DataSet();
data = oDa.TampilDir(akode);
ddDir.ItemsSource = data.Tables[0].DefaultView;
ddDir.DisplayMemberPath = data.Tables[0].Columns["unit_kerja"].ToString();
ddDir.SelectedValuePath = data.Tables[0].Columns["kode"].ToString();
ddSubDir.SelectedIndex = -1;
ComboBoxItem cbi = (ComboBoxItem)ddDeputi.ItemContainerGenerator.ContainerFromItem(ddDeputi.SelectedItem);
txtDeputi.Text = cbi.Content.ToString();
}
}