简体   繁体   English

Xamdatagrid中的MultiBinding

[英]MultiBinding in Xamdatagrid

In my XamDataGrid I have an unboundField with multiBinding one item comes from the collection XamDataGrid is binded into, and the other "SelectedPipeMode" comes from a property in the viewmodel. 在我的XamDataGrid中,我有一个带有multiBinding的unboundField,其中一项来自XamDataGrid绑定到的集合,另一项“ SelectedPipeMode”来自于viewmodel中的一个属性。 which means it has a different dataContext than the collection 这意味着它与集合具有不同的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>

I want to convert my XamdataGrid into a userControl since I'm going to reuse it. 我想将XamdataGrid转换为userControl,因为我将重用它。

this is how I use my new user control: 这就是我使用新用户控件的方式:
<sensorResolutionTables:SensorResolutionsTablesUserControl Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6" DataContext="{Binding SensorResolutionTablesViewModel}"/>

Can you see my mistake? 你能看到我的错误吗?

Here is my error: 这是我的错误:

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')

Sorry to provide an answer so late, but I just faced the same issue and maybe it might be useful to others as well. 抱歉,这么晚才提供答案,但我只是遇到了同样的问题,也许对其他人也可能有用。

First, it is not YOUR mistake, is more about the grid binding definition which is kind of weird sometime, IMO. 首先,不是您的错误,更多的是关于网格绑定定义,IMO在某些时候有点奇怪。

Your binding will work if placed inside of a CellValuePresenter Template by using a static resource. 如果通过使用静态资源将绑定放置在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>

Pay attention to one of your original MultiBinding Path that have been updated with DataItem. 请注意您的原始MultiBinding Path之一已被DataItem更新。 prefix ! 字首 !

Then your XamDataGrid UnboundField binding should look like : 然后,您的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 HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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