VS 2012で、Code FirstEntityFrameworkとリポジトリおよびMVVMパターンを使用するWPFアプリケーションを構築しています。
EntityTypeとLicenseTypeの2つのクラスがあります。
EntityTypeは、次のように指定されます。
private int _id;
private string _name;
private string _description;
private List<LicenseType> _licenseTypes = new List<LicenseType>();
LicenseTypeは次のように宣言されます:
private int _id;
private string _name;
private string _description;
そして、これらのプライベートフィールドに対して宣言されたパブリックプロパティがあります。
ObservableCollectionをCheckedListBox(Syncfusion製品)にバインドしています。
問題ない。
その下で、別のCheckedListBoxをObservableCollectionにバインドしています。
繰り返しますが、問題ありません。
私ができないことは、その特定のLicenseTypeがEntityType.LicenseTypesのコレクションにあるかどうかに基づいて、LicenseTypeリストボックスのCheckListBoxItemのIsSelectedプロパティをtrueに設定することです(これにより、チェックボックスを「チェック」します)。
CheckedListBoxのコードは次のとおりです。
<syncfusion:CheckListBox x:Name="lstAllLicenseTypes" ItemsSource="{Binding AllLicenseTypes}" DisplayMemberPath="Name" >
<syncfusion:CheckListBox.ItemContainerStyle>
<Style TargetType="syncfusion:CheckListBoxItem">
<Setter Property="IsSelected" Value="{Binding ????}"/>
</Style>
</syncfusion:CheckListBox.ItemContainerStyle>
</syncfusion:CheckListBox>
2つの方法を試しました。最初の方法は、LicenseTypeリストボックスの各項目をループし、EntityTypeのLicenseTypeコレクションとの関連付けがあるかどうかを確認し、XAMLにバインドされたプロパティ値を設定することです。
private void ListEntityTypes_OnSelectionChanged(object sender、SelectionChangedEventArgs e){var thisEntity =(EntityType)listEntityTypes.SelectedItems [0];
foreach (object t in lstAllLicenseTypes.Items)
{
bool hasAssociation = _vmEntityTypes.EntityHasAssociationWithThisLicenseType(thisEntity,(LicenseType) t);
if (hasAssociation)
{
_vmEntityTypes.CurrentEntityIsAssociatedWithCurrentLicenseType = true;
}
else
{
_vmEntityTypes.CurrentEntityIsAssociatedWithCurrentLicenseType = false;
}
}
}
ここでの目的は、プロパティ「CurrentEntityIsAssociatedWithCurrentLicenseType」にバインドすることです。これは機能しませんでした。CheckedListBoxの各項目についてプロパティ値が更新されたため、最終的にはfalseであり、項目がチェックされなかったため、機能しなかったと思います。
他のアプローチは上記と同様でしたが、リストボックスアイテムを手動で「チェック」しようとしましたが、LicenseTypeをCheckListItemにキャストして戻すことはできませんでした。
一般に、私が苦手なのは、他のデータコレクションに関連するレコードのコレクションを操作し、ユーザーがさまざまなテーブルを明確に追加して関連付けることができるインターフェイスを構築することです。
どんな助けも素晴らしいでしょう、
ありがとう!ポール