ラジオボタンに基づいて顧客またはサプライヤのリストを作成しようとしています。 1つのリストをコンボボックスにバインドすると、そのコンボボックスが機能します。データトリガーを使用して表示するコレクションを動的に変更しようとすると、何も起こりません。2つのアイテムソースを持つコンボボックス
別のリストは変更されないコンボボックスで動作するので、私はすでにそれがデータ型の問題ではないことを知っています。私はFody Weaverをインストールして、自動的にINotifyPropertiesを作成しました。
XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<RadioButton Content="Klant"
Grid.Column="0"
Foreground="White"
Margin="10"
IsChecked="{Binding ButtonCustomerIsChecked}"
GroupName="CustomerSupplier"
Name="RadioButtonCustomer"
/>
<RadioButton Content="Leverancier"
Grid.Column="1"
Foreground="White"
Margin="10"
IsChecked="{Binding ButtonSupplierIsChecked}"
GroupName="CustomerSupplier"
Name="RadioButtonSupplier"
/>
</Grid>
<ComboBox ItemsSource="{Binding SupplierList}"
DisplayMemberPath="Name"
SelectedItem="{Binding Path=SelectedCustomerSupplier}"
Style="{StaticResource InputComboBox}"
/>
<ComboBox Style="{StaticResource InputComboBox}"
ItemsSource="{Binding}"
DisplayMemberPath="Name"
>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=ButtonCustomerIsChecked, diag:PresentationTraceSources.TraceLevel=High}" Value="True">
<Setter Property="ItemsSource" Value="{Binding CustomerList}"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsChecked, ElementName=ButtonSupplierIsChecked, diag:PresentationTraceSources.TraceLevel=High}" Value="True">
<Setter Property="ItemsSource" Value="{Binding SupplierList}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox>
C#(ビューモデル):
CustomerList = new ObservableCollection<Customer>
{
new Customer{Id=1, Name="Bart"},
new Customer{Id=1, Name="Nick"},
new Customer{Id=1, Name="Erwin"},
};
SupplierList = new ObservableCollection<Customer>
{
new Customer{Id=1, Name="Rita"},
new Customer{Id=1, Name="Sascha"},
new Customer{Id=1, Name="Didier"},
};
以上のC#(Customerクラス):
public class Customer : IStakeholder
{
/// <summary>
/// The ID of the customer
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the customer
/// </summary>
public string Name { get; set; }
/// <summary>
/// The phone number
/// </summary>
public string PhNr { get; set; }
/// <summary>
/// The VAT number
/// can be null
/// </summary>
public string VatNr { get; set; }
/// <summary>
/// The country where the customer is located
/// </summary>
public CountryCat CountryCat { get; set; }
/// <summary>
/// A list of payments made by the customer
/// </summary>
public List<IPayments> Payments { get; set; }
}
[価値優先](https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-value-precedence)の問題に遭遇し、初期プロパティの割り当てをスタイルセッター。 – Sinatr
詳細を教えてください。私はXAML/C#をかなり新しくしています。そして、あなたが意味する最初のプロパティの割り当てがわかりません。 –