Xamdatagrid 中的多重绑定
MultiBinding in Xamdatagrid
在我的 XamDataGrid 中,我有一个带有 multiBinding 的 unboundField,其中一项来自 XamDataGrid 绑定到的集合,另一项 "SelectedPipeMode" 来自视图模型中的 属性。这意味着它具有与集合不同的 dataContext
<igWPF:UnboundField Label="Pipe Output Width/Height" Width="auto">
<igWPF:UnboundField.Binding>
<MultiBinding Converter="{StaticResource settingsOutputResToStringConverter}" >
<Binding Path="Key"/>
<Binding Path="SelectedPipeMode" RelativeSource="{RelativeSource AncestorType=sensorResolutionTables:SensorResolutionsTablesUserControl}"/>
</MultiBinding>
</igWPF:UnboundField.Binding>
<igWPF:UnboundField.Settings>
<igWPF:FieldSettings AllowEdit="False" SortComparer="{StaticResource customFilterComparer}" >
</igWPF:FieldSettings>
</igWPF:UnboundField.Settings>
</igWPF:UnboundField>
我想将 XamdataGrid 转换为 userControl,因为我要重用它。
这是我使用新用户控件的方式:
<sensorResolutionTables:SensorResolutionsTablesUserControl Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6" DataContext="{Binding SensorResolutionTablesViewModel}"/>
你能看出我的错误吗?
这是我的错误:
System.Windows.Data Warning: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='SkyCamWorkFlow.SensorResolutionTables.SensorResolutionsTablesUserControl', AncestorLevel='1''. BindingExpression:Path=SelectedPipeMode; DataItem=null; target element is 'ValueHolderWithDataContext' (HashCode=1650399); target property is 'Value' (type 'Object')
很抱歉这么晚才提供答案,但我刚遇到同样的问题,也许它对其他人也有用。
首先,这不是你的错,更多的是关于网格绑定定义,IMO 有时有点奇怪。
如果使用静态资源将绑定放置在 CellValuePresenter 模板中,您的绑定将起作用。
<Style x:Key="PipeOutputPresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource settingsOutputResToStringConverter}" >
<Binding Path="DataItem.Key"/>
<Binding Path="SelectedPipeMode" RelativeSource="{RelativeSource AncestorType=sensorResolutionTables:SensorResolutionsTablesUserControl}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
注意已使用 DataItem 更新的原始 MultiBinding Path 之一。前缀 !
那么您的 XamDataGrid UnboundField 绑定应该如下所示:
<igWPF:UnboundField Label="Pipe Output Width/Height" Width="auto">
<igWPF:UnboundField.Settings>
<igWPF:FieldSettings
CellValuePresenterStyle="{StaticResource PipeOutputPresenterStyle}"
AllowEdit="False" SortComparer="{StaticResource customFilterComparer}" />
</igWPF:UnboundField.Settings>
</igWPF:UnboundField>
HTH
在我的 XamDataGrid 中,我有一个带有 multiBinding 的 unboundField,其中一项来自 XamDataGrid 绑定到的集合,另一项 "SelectedPipeMode" 来自视图模型中的 属性。这意味着它具有与集合不同的 dataContext
<igWPF:UnboundField Label="Pipe Output Width/Height" Width="auto">
<igWPF:UnboundField.Binding>
<MultiBinding Converter="{StaticResource settingsOutputResToStringConverter}" >
<Binding Path="Key"/>
<Binding Path="SelectedPipeMode" RelativeSource="{RelativeSource AncestorType=sensorResolutionTables:SensorResolutionsTablesUserControl}"/>
</MultiBinding>
</igWPF:UnboundField.Binding>
<igWPF:UnboundField.Settings>
<igWPF:FieldSettings AllowEdit="False" SortComparer="{StaticResource customFilterComparer}" >
</igWPF:FieldSettings>
</igWPF:UnboundField.Settings>
</igWPF:UnboundField>
我想将 XamdataGrid 转换为 userControl,因为我要重用它。
这是我使用新用户控件的方式:
<sensorResolutionTables:SensorResolutionsTablesUserControl Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6" DataContext="{Binding SensorResolutionTablesViewModel}"/>
你能看出我的错误吗?
这是我的错误:
System.Windows.Data Warning: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='SkyCamWorkFlow.SensorResolutionTables.SensorResolutionsTablesUserControl', AncestorLevel='1''. BindingExpression:Path=SelectedPipeMode; DataItem=null; target element is 'ValueHolderWithDataContext' (HashCode=1650399); target property is 'Value' (type 'Object')
很抱歉这么晚才提供答案,但我刚遇到同样的问题,也许它对其他人也有用。
首先,这不是你的错,更多的是关于网格绑定定义,IMO 有时有点奇怪。
如果使用静态资源将绑定放置在 CellValuePresenter 模板中,您的绑定将起作用。
<Style x:Key="PipeOutputPresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource settingsOutputResToStringConverter}" >
<Binding Path="DataItem.Key"/>
<Binding Path="SelectedPipeMode" RelativeSource="{RelativeSource AncestorType=sensorResolutionTables:SensorResolutionsTablesUserControl}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
注意已使用 DataItem 更新的原始 MultiBinding Path 之一。前缀 !
那么您的 XamDataGrid UnboundField 绑定应该如下所示:
<igWPF:UnboundField Label="Pipe Output Width/Height" Width="auto">
<igWPF:UnboundField.Settings>
<igWPF:FieldSettings
CellValuePresenterStyle="{StaticResource PipeOutputPresenterStyle}"
AllowEdit="False" SortComparer="{StaticResource customFilterComparer}" />
</igWPF:UnboundField.Settings>
</igWPF:UnboundField>
HTH