开发者

Multibinding issues with ListViewItems

I've this piece of XAML:

<Style x:Key="HideShowStyle" TargetType="{x:Type ListViewItem}">
        <Style.Resources>
            <localConverters:ShowHideConverter x:Key="showHideConverter" />
        </Style.Resources>

        <Style.Triggers>
            <DataTrigger Value="true">
                <DataTrigger.Binding>
                    <MultiBinding Converter="{StaticResource showHideConverter}">
                        <Binding Path="EndingDate" />
                        <Binding ElementName="cmbType" Path="SelectedValue" />
                        <Binding ElementName="searchBox" Path="Text" />
                        <Binding Path="Client" />
                    </MultiBinding>
                </DataTrigger.Binding>
                <Setter Property="Visibility" Value="Visible" />
            </DataTrigger>

            <DataTrigger Value="false">
                (...)
            </DataTrigger>
        </Style.Triggers>
    </Style>

that I've converted in C# code in:

 开发者_JAVA百科       var triggerStyle = new Style();
        var trueTrigger = new DataTrigger();
        var multiBinding = new MultiBinding();
        var converter = new ShowHideConverter();

        multiBinding.Converter = converter;

        var binding1 = new Binding("SelectedItem");
        binding1.Source = cmbType;
        multiBinding.Bindings.Add(binding1);

        var binding2 = new Binding("EndingDate");
        binding2.Source = reportList.ItemsSource;
        multiBinding.Bindings.Add(binding2);

        var binding3 = new Binding("Text");
        binding3.Source = searchBox;
        multiBinding.Bindings.Add(binding3);

        var binding4 = new Binding("Client");
        binding4.Source = reportList.ItemsSource;
        multiBinding.Bindings.Add(binding4);

        trueTrigger.Value = true;
        trueTrigger.Binding = multiBinding;
        trueTrigger.Setters.Add(new Setter(VisibilityProperty, Visibility.Visible));

        var falseTrigger = new DataTrigger();
        falseTrigger.Value = false;
        falseTrigger.Binding = multiBinding;
        falseTrigger.Setters.Add(new Setter(VisibilityProperty, Visibility.Collapsed));

        triggerStyle.Triggers.Add(trueTrigger);
        triggerStyle.Triggers.Add(falseTrigger);

        reportList.ItemContainerStyle = triggerStyle;

Now, executing the code, the listview pass correctly data into the converter, this analize it and returns true or false based on conditions. The problem is that, the "Client" binding doesn't scroll throught rows, but it remains stuck on the value of the first column, while, the XAML hardcoded style works fine.

I don't have a clue how to do to make it works.


Just remove this line:

binding4.Source = reportList.ItemsSource;

The source of the binding will be the data context of the list view item (which is a data item for each row).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜