当Listview中的List内的Object属性发生更改时,未调用转换器

时间:2018-04-05 20:22:36

标签: wpf listview binding converter observablecollection

TemplateSwitcher
                 ShowAlternativeTemplate="{Binding Options, Converter={StaticResource ListToVisibilityConverter}}">
                TemplateSwitcher.AlternativeTemplate starts
                            shows a watermark  // Line A
                TemplateSwitcher.AlternativeTemplate ends
                // actual template which shows up if alternative template is not the case
                ScrollViewer
                    ListView
                        // SHows a list of options and with each option , there are two buttons - Accept option/ Reject option
                        /* Clicking on Accept sets the isOptionAccepted to true; */
                    ListView ends
                ScrollViewer ends
Tempalte switcherends
  • 选项 = ObservableCollection EachOption 类型; EveryOption 有一个bool?字段叫 isOptionAccepted

我想要实现的目标是:

  • 页面加载时:如果选项字段为空/空:显示 替代模板(水印),如XAML中的A行//正确发生
  • 当用户点击“接受”时 选项:UI中的列表不应显示此选项。然而, ObservableCollection中的其他选项仍然出现。我通过将每个listviewitem的可见性绑定到 isOptionAccepted 字段
  • 来实现这一点。

现在,当所有选项被接受时,这意味着UI中不会显示任何选项,这是正确发生的。但是,因此我希望它在XAML的A行显示替代模板(水印)。我无法实现这一点。

看一下this示例,但我仍无法解决此问题。使用此转换器,选项根本不会显示在列表中。我在转换器中设置了一个断点,每当我点击Accept时我都希望达到断点(因为那是修改对象的属性 EachOption )  任何帮助表示赞赏。

以下是ListToVisibilityConverter

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return true;
        else
        {
            ObservableCollection<EachOption> optionList= value as ObservableCollection;
            if (optionList != null)
            {
                foreach (EachOption eachOpt in optionList)
                {
                    if (eachOpt.isOptionAccepted!= true)
                        return true;
                    else
                        return false;
                }
            }
        }
        return true;
    }          

0 个答案:

没有答案