简体   繁体   中英

ValueConverter only firing once

I have a WPF value converter to convert items of an items control which is firing when the xaml view is loaded.

My issue is that the value converter appears not to be firing when the itemssource collection raises a notify property changed event.

Here is my xaml:

<ItemsControl ItemsSource="{Binding StackupViewModel.Layers}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <ContentPresenter>
                <ContentPresenter.Content>
                    <MultiBinding Converter="{StaticResource LayerToRectangle}">
                        <Binding />
                        <Binding ElementName="rgv"/>
                    </MultiBinding>
                </ContentPresenter.Content>
            </ContentPresenter>
        </DataTemplate>
    </ItemsControl.ItemTemplate>

Here is my converter

public object Convert(
        object[] values,
        Type targetType,
        object parameter,
        System.Globalization.CultureInfo culture)
    {
        var layer = values.First() as Layer;
        var radGridView = values[1] as RadGridView;
        var column = radGridView.Columns["Lamination"];
        var row = radGridView.Items[0];
        var cellToEdit = new GridViewCellInfo(row, column, radGridView);
        radGridView.CurrentCellInfo = cellToEdit;
        radGridView.Focus();

        Rectangle rectangle = new Rectangle();

        if (radGridView.CurrentCell != null)
        {
            Point p = radGridView.CurrentCell.TranslatePoint(new Point(0, 0), radGridView);
            rectangle.Height = radGridView.RowHeight - 10;
            rectangle.Width = column.ActualWidth;
            rectangle.Fill = (SolidColorBrush)new BrushConverter().ConvertFrom(layer.ColorHex);
            Canvas.SetTop(rectangle, p.Y + layer.LayerNumber);
            Canvas.SetLeft(rectangle, p.X);
        }





        return rectangle;
    }

I added a button to the xaml to fire the notifypropertychanged on the Layers observable collection as so:

<Button Name="btnDraw" Command="{Binding StackupViewModel.ScrollCommand}" />

private void ScrollCommandHandler(object offset)
{
    RaisePropertyChanged(() => this.Layers);

}

Can anyone advise me why the converter isn't getting fired when the button is clicked?

第一个绑定的上下文只是一个单独的Layer对象,而不是Layers父集合,因此,当您调用ScrollCommandHandler方法时,MultiBinding将不会注册任何PropertyChanged

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM