I have a listview with Combobox in it:
<ListView x:Name="DiscountListView" Grid.Row="1" ItemsSource="{Binding DiscountMatrix.RelatedDiscounts}" Margin="0, 7, 0, 0" Style="{StaticResource AppTransparentListViewStyle}"> <ListView.View> <GridView> <GridViewColumn Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor , AncestorType=ListView, AncestorLevel=1},Path=ActualWidth}"> <GridViewColumn.CellTemplate> <ItemContainerTemplate> <Grid HorizontalAlignment="Stretch" Margin="-7, 14, 0, 0" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor , AncestorType=ListViewItem, AncestorLevel=1},Path=ActualWidth}"> <Border BorderBrush ="{Binding SelectedDiscount.IsNotRelated, Converter={StaticResource DisablingBoolToColorConverter}}" BorderThickness="2" Margin="4, 0, 15, 0"> <customComboBox:CustomComboBox x:Name="DiscountView" DisplayMemberPath="Name" Margin="0, 8, 5, 0" Text="{Binding SelectedDiscount.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValue ="{Binding SelectedDiscount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <customComboBox:CustomComboBox.ItemsSource> <CompositeCollection> <ComboBoxItem Content="{DynamicResource lang_Common_SelectItem}" IsEnabled="False" /> <CollectionContainer Collection="{Binding Source={StaticResource Discounts}}" /> </CompositeCollection> </customComboBox:CustomComboBox.ItemsSource> </customComboBox:CustomComboBox> </Border> </Grid> </ItemContainerTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> </Grid> According to my logic RelatedDiscounts (actually my listview) is a list of SelectedDiscounts. I can add a discount and it will be set as SelectedItem in my Combobox (for this I should ovverride Equals in SelectedDiscount class). Every discount has IsNotRelated property (true/false depending on logic). I faced with a problem: f.e. my first list item SelectedDiscount was set as a SelectedItem in the first Combobox and it's IsNotRelated property is false by logic. Then I add the same item as SelectedItem to my second Combobox but IsNotRelated property is true. In this case first SelectedDiscount's property IsNotRelated becomes also true but should stay false. I know it's because the second time I set true for SelectedDiscount property from ItemSourse of all my Comboboxes. My question is: how can I set property only for SelectedItem of current Combobox but not for this item in ItemSourse at all? Any ideas how can I avoid standart behavior of Combobox and sorry for my English.
Here is a part of SelectedDiscount's type (DiscountModel):
public bool _isNotRelated; [JsonIgnore] public bool IsNotRelated { get { return _isNotRelated; } set { _isNotRelated = value; RaisePropertyChangedEvent("IsNotRelated"); } } public override bool Equals(object obj) { var other = obj as DiscountModel; return (Id == other?.Id); }