Xamdatagrid中的MultiBinding

时间:2015-03-09 08:39:51

标签: c# wpf infragistics

在我的XamDataGrid中,我有一个带有multiBinding的unboundField,一个项来自XamDataGrid绑定到的集合,另一个“SelectedPipeMode”来自viewmodel中的一个属性。这意味着它具有与集合

不同的dataContext
 <igWPF:UnboundField Label="Pipe Output&#10;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')

1 个答案:

答案 0 :(得分:1)

很抱歉这么晚才提供答案,但我刚遇到同样的问题,也许对其他人也有帮助。

首先,它不是你的错误,更多的是网格绑定定义,有时候很奇怪,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&#10;Width/Height" Width="auto">
  <igWPF:UnboundField.Settings>
    <igWPF:FieldSettings 
      CellValuePresenterStyle="{StaticResource PipeOutputPresenterStyle}"
      AllowEdit="False" SortComparer="{StaticResource customFilterComparer}"  />
  </igWPF:UnboundField.Settings>
</igWPF:UnboundField>

HTH