DataGrid refresh issue

2019-08-19 08:40发布

I have a Silverlight 4 DataGrid which has its ItemsSource bound to an ObservableCollection. When i modify an element of my ObservableCollection the modified element is correctly displayed inside my grid except the element of one column. This columns differs from the others in the way it is a TemplateColumn and it's using a ValueConverter.

The Template for the column consists of a simple stackPanel that includes a Path control and a Label. And the Label is bound to some Source object with the help of a simple ValueConverter.

The problem now is when i modify some element that belongs to the ObservableCollection all columns of the grid are displayed correctly except the one described above. It simply stays unchanged - but when i use the mousecursor to select the DataGridCell and click it a second time, the desired refresh suddenly happens.

So I guess it's something simple what i am missing here, but I can't find it ...

Thanks in advance ..

EDIT:

In the meanwhile I was able to further locate the problem: It seems that after I modify an element of my ObservableCollection the corresponding ValueConverter that belongs to the label that is in my grid that is bound to the source is simply not called. When i click inside the cell the ValueConverter is getting called as it should. BUT it won't automatically - So how do I achieve that ? please help :)

EDIT:

The binding:

<sdk:Label Content="{Binding Route.Legs, Converter={StaticResource IncomingTableRouteTripConverter}}" Margin="9,0,0,0" Style="{StaticResource TripLabelTemplate}" FontFamily="Arial" FontSize="10.667" Padding="0" Height="10" FontWeight="Bold" />

This is the code of my ValueConverter: (But I don't think that the code of the converter has anything to do with my problem I only posted it here for completeness)

public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {

        string trip = "";

        if (value != null) {


            List<Leg> legs = (List<Leg>)value;

            if (legs.Count >= 1) {

                for (int i = 0; i <= legs.Count - 1; i++) {

                    trip += ((Leg)legs[i]).Start.ICAO + " - " + ((Leg)legs[i]).Stop.ICAO + " - ";
                }

                trip = trip.Substring(0, trip.Length - 2);
            }
        }

        return trip;
    }

2条回答
够拽才男人
2楼-- · 2019-08-19 08:48

For all nodes in the Path notifications need to be in place, so both the class owning Route and the class owning Legs need to implement INPC.

Further if you add items to the Legs list naturally nothing will be updated, in fact even if the Legs property were of type ObservableCollection<...> that would not matter as the binding engine only cares about INPC.

So if you want the binding to update if the collection changes you need to fire property changed for the Legs property every time it somehow is modified (including a complete replacement of the reference).

查看更多
叛逆
3楼-- · 2019-08-19 08:48

IF you use like

Content="{Binding Path=Parameter Converter={StaticResource SomeConverter}}"

then your problem might be solved...

查看更多
登录 后发表回答