私はこれを実現するために過去2日間を費やしましたが、何が欠けているのか理解できません。グリッドを使用したWPFユーザーコントロールがあり、そのグリッド内にテキストボックスとコンボボックスがあります。グリッドのDataContextは、オブジェクトを使用してC#コードで設定され、テキストボックスをグリッドのDataContextオブジェクトに双方向でバインドすることができました。ここにいくつかのサンプルコードがあります。ClinicInfoRootに入るオブジェクトは私のClinicオブジェクトであり、そのプロパティの1つはStateIDです(これはすぐに重要です)
private void Events_ClinicSelected( object sender, ClinicSelectedEventArgs e )
{
if ( !DesignerProperties.GetIsInDesignMode( this ) )
{
// Get the current logged in user object from arguments and set local
this.CurrentLoggedInPDUser = e.CurrentLoggedInPDUser;
// Bind the patient object to the window grid data context
this.ClinicInfoRoot.DataContext = e.Clinic;
// Set the mode and call mode manager
this.SetMode( Mode.View );
this.ModeManager();
}
}
xamlの場合:
<Grid Name="ClinicInfoRoot"
Margin="0,0,10,10"
Validation.Error="ClinicInfoRoot_Error">
<TextBox Margin="82,28,0,0"
Name="txtName"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Width="82" >
<TextBox.Text>
<Binding Path="Name"
Mode="TwoWay"
ValidatesOnDataErrors="True"
ValidatesOnExceptions="True"
NotifyOnValidationError="True"
UpdateSourceTrigger="PropertyChanged"></Binding>
</TextBox.Text>
</TextBox>
<ComboBox HorizontalAlignment="Left"
Margin="281,141,0,0"
Name="cbState"
VerticalAlignment="Top"
Width="73"
ItemsSource="{Binding Mode=OneWay}"
DisplayMemberPath="Abbrev"
SelectedValuePath="StateID" >
<ComboBox.SelectedValue>
<Binding ElementName="ClinicInfoRoot"
Path="Clinic.StateID"
Mode="TwoWay"
ValidatesOnDataErrors="True"
ValidatesOnExceptions="True"
NotifyOnValidationError="True"
UpdateSourceTrigger="PropertyChanged"></Binding>
</ComboBox.SelectedValue>
</ComboBox>
Clinicオブジェクトの適切なプロパティでテキストボックスをバインドできましたが、問題はStateコンボボックスにあります。ItemsSourceを別のオブジェクトの状態のリストにバインドしましたが、コンボボックスは正しくいっぱいになります。ただし、ClinicオブジェクトのStateIDプロパティでコンボボックスに表示される内容を設定したいのですが、SelectedValueのElementNameプロパティとPathプロパティを理解できません。
コンボボックスのSelectedValueのバインディングのElementNameとPathの構文は何ですか?