首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamdatagrid中的MultiBinding

Xamdatagrid中的MultiBinding
EN

Stack Overflow用户
提问于 2015-03-09 08:39:51
回答 1查看 838关注 0票数 0

在我的XamDataGrid中,我有一个带有multiBinding的unboundField,一个项来自XamDataGrid绑定到的集合,另一个"SelectedPipeMode“来自视图模型中的一个属性。这意味着它具有与集合不同的dataContext。

代码语言:javascript
复制
 <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}"/>

你能看到我的错误吗?

以下是我的错误:

代码语言:javascript
复制
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')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-06 10:47:04

很抱歉这么晚才给出答案,但我也面临着同样的问题,也许这对其他人也有帮助。

首先,这不是你的错误,更多的是关于网格绑定的定义,这有时有点奇怪,海事组织。

如果使用静态资源将绑定放置在CellValuePresenter模板中,则绑定将工作。

代码语言:javascript
复制
<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绑定应该如下所示:

代码语言:javascript
复制
<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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28937904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档