When value of one of mentioned objects changes (and is different) problem doesn't exist, ListView treat them as it should.
XAML code is simple:
<ListView x:Name="listViewSimpleExpression" Grid.Row="1" |
ItemsSource="{Binding}" |
Background="Lavender" |
SelectionMode="Single"> |
<ListView.View> |
<GridView AllowsColumnReorder="false"> |
<GridViewColumn Width="Auto" |
Header="Column specification"> |
(...) |
</ListView> |
C# code behind:
public ObservableCollection<Travelplanet.Import.Itaka.OfferLine.IExpression> _observableInnerExpressions; |
public ObservableCollection<Travelplanet.Import.Itaka.OfferLine.IExpression> ObservableInnerExpressions |
{ |
get |
{ |
if (_observableInnerExpressions == null) |
{ |
if (DataContext == null) |
{ |
return null; |
} |
//Get list of simple expressions from multiargument expression from rule |
Rule rule = (Rule)DataContext; |
MultiargumentExpression multiExpression = (MultiargumentExpression)rule.Expression; |
_observableInnerExpressions |
= new ObservableCollection<IExpression>(multiExpression.InnerExpressions); |
} |
return _observableInnerExpressions; |
} |
} |
And method that adds new object to collection:
/// <summary> |
/// COMMAND CREATE PART-EXPRESSION (create simple expression) |
/// Create part expression button functionality |
/// </summary> |
private void CmdCreatePartExpression_Executed(object sender, ExecutedRoutedEventArgs e) |
{ |
ColumnSpecification columnSpecification = new ColumnSpecification(String.Empty, String.Empty, String.Empty); |
NumberExpression numberExpression = new NumberExpression(columnSpecification, NumberComparisonOp.Equal, 0); |
_observableInnerExpressions.Add(numberExpression); |
listViewSimpleExpression.DataContext = _observableInnerExpressions; |
e.Handled = true; |
} |
There are two posibilities for this:
1. NumberExpression is an struct
2. NumberExpression has overriden GetHashcode and Equals
Then both objects are equal even if the reference is different
No comments:
Post a Comment