开发者

Converter with collection

开发者 https://www.devze.com 2023-04-13 05:34 出处:网络
in WPF, in my XAML i have a dataGrid binded on a IEnumerable. The collection items have a proprety call开发者_开发知识库ed Sealed. To know if the order is sealed or not. So i\'ve made a converter to s

in WPF, in my XAML i have a dataGrid binded on a IEnumerable. The collection items have a proprety call开发者_开发知识库ed Sealed. To know if the order is sealed or not. So i've made a converter to switch it from one list to another. Altought, when i change the collection from the outside the converter is not being called. But if i close and reopen the window it works fine.

      public object Convert(object value, Type targetType, object parameter,   System.Globalization.CultureInfo culture)
    {
        var collection = (ObservableCollection<OrderEntry>)value;
        var viewSource = new CollectionViewSource()
        {
            Source = collection,
        };
        viewSource.Filter += new FilterEventHandler(FilterInSealedOrderEntries);
        return viewSource.View;
    }

    private static void FilterInSealedOrderEntries(object sender, FilterEventArgs e)
    {
        var orderEntry = e.Item as OrderEntry;
        e.Accepted = orderEntry != null && orderEntry.Sealed;
    }

"{Binding Path=OrderEntries.Collection, Converter={StaticResource ViewNotSealedOrderEntryCollectionValueConverter}}"

In my Xaml.

Whenever i change the property, the collectionContentChanged is being called but not the converter, any idea what am i doing wrong?

Thanks, i will comment if it's not clear enough.


Because your specifying the ValueConverter in the Binding for the DataGrid ItemsSource it will only be called on initially populating the items.


IValueConverter interface also contains ConvertBack method. I don't see this method in your code

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号