Accountという新しいクラスレコードを作成するために使用しているいくつかのフィールドを含むページがあります。フィールドの1つは、コンボボックスを介して設定される通貨コードです。コンボボックスは、IDと説明を含むデータテーブルにバインドされます。コンボボックスの選択された値がAccountクラスの通貨IDを自動的に更新するように、バインディングを使用しようとしています。これまでのところ喜びはありません...
クラス定義:
class Account : IDataErrorInfo
{
public String Name { get; set; }
public int CurrencyID { get; set; }
public int BankID { get; set; }
public String AccountNumber { get; set; }
public decimal OpeningBalance { get; set; }
... other definitions for validation handling ...
}
コンボボックスの定義:
<ComboBox x:Name="cboCurrency" Grid.Column="1" Grid.Row="1" Width="250" HorizontalAlignment="Left"
SelectedValue="{Binding Path=Account.CurrencyID, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, NotifyOnValidationError=true}"
ToolTip="{Binding ElementName=cboCurrency, Path=(Validation.Errors)[0].ErrorContent}"/>
ページコンストラクター:
public AccountAdd()
{
InitializeComponent();
base.DataContext = new Account();
// Load the Currency combo with the list of currencies
//
cboCurrency.DisplayMemberPath = "Name";
cboCurrency.SelectedValuePath = "_id";
cboCurrency.ItemsSource = _DBUtils.getCurrencyList().DefaultView;
}
コードを保存:
private void btnAccountOK_Click(object sender, RoutedEventArgs e)
{
Account newAccountRec = (Account)base.DataContext;
int newid = _DBUtils.AddAccount(newAccountRec);
}