سؤال

I've got a static ObservableCollection> named HeaderColorPairs in the non-static class ColorManager (singleton).

This property is bound to a ListView's ItemsSource like this:

        <ListView.ItemsSource>
            <MultiBinding Converter="{StaticResource xmlFormatter}" ConverterParameter="ColorList">
                <Binding Source="{StaticResource ResourceKey=colorManager}" Path="HeaderColorPairs"></Binding>
                <Binding Path="LogEntryListViewModel.SelectedLogEntry.Model.RawXml"></Binding>
            </MultiBinding>
        </ListView.ItemsSource>

That's the Convert-Method:

public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
    {
        //parameter = outputtype
        parameter = (parameter == null) ? "" : parameter;
        string rawXml = value[1].ToString();
        if (rawXml != DependencyProperty.UnsetValue.ToString() && rawXml != string.Empty)
        {
            OutputTypes opt = (OutputTypes)Enum.Parse(typeof(OutputTypes), parameter.ToString().Length.ToString());
            if (opt == OutputTypes.Xml)
            {
                RawXmlFormatter rxf = new RawXmlFormatter(rawXml);
                return rxf.XmlStringArrayToRunList();
            }
            else if (opt == OutputTypes.ColorList)
            {
                return ColorManager.GetColorsRelatedToXml(rawXml);
            }
        }
        return null;
    }


public static ObservableCollection<KeyValuePair<string, Color>> GetColorsRelatedToXml(string rawXml)
    {
        List<string> headerList = RawXmlFormatter.GetHeadersFromRawXml(rawXml);
        SetUnsetColors(headerList);
        return new ObservableCollection<KeyValuePair<string, Color>>(HeaderColorPairs.Where(kvp => headerList.Contains(kvp.Key)));
    }

The binding works great, it displays the ObservableCollection right, but if I'm changing the collection in code-behind, the ListView wont update.

هل كانت مفيدة؟

المحلول

Instead of the singleton pattern (which worked also) I do now use a non-static property, which works perfectly. Question solved ;)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top