在我的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')发布于 2015-11-06 10:47:04
很抱歉这么晚才给出答案,但我也面临着同样的问题,也许这对其他人也有帮助。
首先,这不是你的错误,更多的是关于网格绑定的定义,这有时有点奇怪,海事组织。
如果使用静态资源将绑定放置在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>请注意使用MultiBinding更新的原始DataItem路径之一。前缀!
那么您的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
https://stackoverflow.com/questions/28937904
复制相似问题