带条件的多重绑定

时间:2012-07-15 03:52:48

标签: wpf binding multibinding

我在TextBlock中有WPF,并且此TextBlock的绑定文本属性为多依赖项属性。 我想绑定这些依赖属性条件。换句话说,我希望每次将一些依赖属性绑定到TextBlock对象的text属性。我该怎么办?

编辑1:

我的TextBlock位于下方。我通过绑定依赖属性的调查值来计算该文本块的文本属性。并希望通过更改每个绑定依赖项属性来刷新textblock的文本。一些绑定依赖属性可能是null值,我不想将此依赖属性绑定到我的text属性。当我调试我的应用程序和依赖属性为空时Visual Studio在输出窗口中引发警告。

<TextBlock>
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource OCDFLinkTextConverter}">
                    <Binding Path="TbOCDFLink" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.FromOCDFObjectItem.OCDFObject.XPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.FromOCDFObjectItem.OCDFObject.YPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.ToOCDFObjectItem.OCDFObject.XPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.ToOCDFObjectItem.OCDFObject.YPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.FromOCDFObjectItem.OCDFObject.ParentOCDFObject.XPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.FromOCDFObjectItem.OCDFObject.ParentOCDFObject.YPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.ToOCDFObjectItem.OCDFObject.ParentOCDFObject.XPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.ToOCDFObjectItem.OCDFObject.ParentOCDFObject.YPosition" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.TbOCDFLinkGroup.FromOCDFObjectItem" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                    <Binding Path="TbOCDFLink.TbOCDFLinkGroup.ToOCDFObjectItem" RelativeSource="{RelativeSource AncestorType=ocdfcontrol:OCDFLink}"/>
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>

1 个答案:

答案 0 :(得分:1)

您好在转换器中尝试此操作

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     string result="";
     if (values != null)
     {
         foreach (var val in values)
         {
             if (val == null)
                 continue;
             else
                 result = result + val;

         }
     }
     return result;
 }

我希望你的所有约束力都在起作用。我希望这会有所帮助。