Code Bye

WPF 多重绑定

大家帮看下,为什么在转换器中不能获取第二个参数的值!
 <Grid>
        <dxg:GridControl Name="dgResistance"  >
            <dxg:GridControl.View>
                <dxg:TableView Name="tvResistance" AllowPerPixelScrolling="True" AllowEditing="False" ShowTotalSummary="False" ShowGroupPanel="False"/>
            </dxg:GridControl.View>
            <dxg:GridControl.Columns>
                <dxg:GridColumn Header="物料编码" FieldName="Code" />
                <dxg:GridColumn Header="label信息" FieldName="LabelMessage"/>
                <dxg:GridColumn Header="功率" FieldName="Power" x:Name="cellPower">                  
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Value}" >
                                <TextBlock.Foreground>
                              <MultiBinding Converter="{StaticResource ColorChoiceConvert}">
                                        <Binding Path="Value"/>
                                        <Binding Path="Value"  ElementName="cellK3Model"/>
                                    </MultiBinding>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn Header="阻值" FieldName="ResistanceValue"/>
                <dxg:GridColumn Header="公差" FieldName="Tolerance"/>
                <dxg:GridColumn Header="K3规格型号" FieldName="K3Model" x:Name="cellK3Model"/>
            </dxg:GridControl.Columns>
        </dxg:GridControl>
    </Grid>
解决方案

20

Power与K3Model  属于同一个类,使用普通绑定即可。  在Converter中接受一个对象,去分别取它的Power与K3Model 的值。相似:
Foreground=”{Binding  DataContext,RelativeSource={RelativeSoure AncestorType=DataGridRow},Converter={StaticeSource xxx}}“

20

model里要有power和k3model,再加一个cellcolor用于绑定单元格背景色。这样只需比较power和k3model两个值即可,比较后根据结果设置cellcolor。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明WPF 多重绑定