ComboBox WPF data binding to DataView

Suppose I have one ComboBox component and 2 TextBox in my GUI. And I have one DataView with data (City, PostalCode, Street, ID). By initializing all this, I populate the DataView with some data :)

City 1, 11111, Street 1, 1
City 1, 22222, Street 2, 2
City 1, 33333, Street 3, 3

Now I want to bind this to my ComboBox. The DataView is a member of the class named m_dvAdresses, but this code does not help:

ItemsSource="{Binding Source=m_dvAdresses}"
SelectedValuePath="ID"
DisplayMemberPath="Street">

I also want my 2 ComboBox objects to display PostalCode and City, depending on what I select in my ComboBox. For example, if I select "Street 2", TextBox1 will show me "City 1" and TexBox2 will show me "22222" ...

How can I bind them all ONLY in WPF code?

+3
source share
2 answers

m_dvAddresses , WPF . WPF CLR WPF DependencyProperty s.

public DataView Addresses
{
     get { return m_dvAddresses; }
}

, WPF, ObservableCollection ( IBindingList). , . : , DataView, .

( ComboBox x:Name="Address"):

<TextBox Text="{Binding SelectedItem.City, ElementName=Address}" />
<TextBox Text="{Binding SelectedItem.Zip, ElementName=Address}" />
+2

, , m_dvAddresses , @sixlettervariables. XAML RelativeSource , ( - Window):

ItemsSource="{Binding Addresses, RelativeSource={RelativeSource AncestorType=Window}}"
Name="cmbAddresses"

<TextBox Name="TextBox1" 
         Text="{Binding SelectedItem.PostalCode, ElementName=cmbAddresses}"/>

TextBox

, :)

0

All Articles