私は申し訳ありませんが、私は間違っていたいくつかの事があるかもしれないので、最初の流れの上にスタックで質問しています。ComboBoxをWPFでバインドしてSelectedItemを取得するにはどうすればよいですか?
私はWPF MVVMの学習を始めましたが、私は立ち往生しています。
データベースには1つのパラメータマスターテーブルがあり、カラムはparameterid
,parametername
、parametertype
です。それはマスタデータが入力されています。たとえば、国マスターはparametertype
"国"、都市は "都市" parametertype
ですが、parameterid
は一意になります。
私はcountryId
とCityId
のパラメータを顧客オブジェクト内に保存するcustomerviewmodelオブジェクトの顧客ページを持っています。私はXAMLからcustomer.CountryId
と直接このparameterId
をバインドするにはどうすればよい
?それとも不可能ですか?
現在、私は以下のように達成しています:
CountrySelectedItem
プロパティを定義し、コンボボックスSelectedItem
でバインドしました。そのプロパティが変更されたときに、誰かがその値を変更すると、ビューモデルで私は顧客のCountryId
をCountrySelectedItem
プロパティに設定しました。お客様の
countryID
プロパティの確認方法を教えてください。コンボボックスでは、パラメータマスタのオブジェクトをバインドしているため、データアノテーションの必須属性をパラメータマスタエンティティに書き込むことができません。ここで
が完了シナリオ
パブリッククラスカスタマー {
public int CustomerId { get; set; }
[Required]
public string CustomerName { get; set; }
[Required]
public int CountryId { get; set; }
}
<telerik:RadComboBox x:Name="cmCountryId" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left"
ItemsSource="{Binding LstCountry}"
HorizontalContentAlignment="Left" VerticalAlignment="Center"
DisplayMemberPath="ParameterName"
SelectedItem="{Binding SelectedCountry,Mode=TwoWay}" Height="25" Width="200" >
</telerik:RadComboBox>
/* To Fill DropDown Country DropDown From ParameterMaster*/
public List<ParameterEntity> LstCountry { get; set; }
LstContainerType = new List<ParameterEntity>(parameterService.GetParamterTypeDetail("COUNTRY").ToList());
/*
Parameter Master has ParameterId,ParameterName,ParameterType -- All Master Data Stored Inside It with Different ParameterType.
*/
/* When User Select CountrId then I Set It's ParameterID As CountryID In My CustomerEntity */
public ParameterEntity SelectedCountry
{
get
{
return _selectedCountry;
}
set
{
_selectedCountry = value;
RaisePropertyChanged("SelectedCountry");
SelectedCustomerEntity.CountryId = _selectedCountry != null ? _selectedCountry.ParameterId : 0;
}
}
So Here Is my question for above Scneraio.
1) To Bind Customer Object's CountryId Property From CountryDropDown is that any other option available then this one.
SelectedCustomerEntity.CountryId = _selectedCountry != null ? _selectedCountry.ParameterId : 0;
// please have a look SelectedCountry property.
Something like , I do not need to write Selected Property and i Can Directly Set ParameterId To CountryId Of CustomerEntity From XAML
Or this one is right scneario.
2) Another Question Is How To do Validation On CountryId ComboBox.
i mean As Mention in CustomerEntity has Required CountryId But In XAMl Design of SelectedItem="{Binding SelectedCountry,Mode=TwoWay}"
What should i write to display if user has not select any country from dropdown. Should I write a logic on Save Button manully ?
あなたの貴重なsuggetionと助けてくれてありがとう、しかし私は私の質問を更新したばかりです –