我有一个WPF值转换器来转换加载xaml视图时触发的items控件的项目。
我的问题是,当itemssource集合引发notify属性更改事件时,值转换器似乎不会被触发。
这是我的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>
这是我的转换器
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;
}
我在xaml上添加了一个按钮来触发Layers observable集合上的notifypropertychanged,如下所示:
<Button Name="btnDraw" Command="{Binding StackupViewModel.ScrollCommand}" />
private void ScrollCommandHandler(object offset)
{
RaisePropertyChanged(() => this.Layers);
}
任何人都可以告诉我为什么转换器在点击按钮时没有被解雇?
答案 0 :(得分:0)
您的第一个绑定的上下文只是一个单独的Layer
对象而不是Layers
父集合,因此当您调用{{1}时,MultiBinding不会注册任何PropertyChanged
}} 方法。