带条件的多重绑定



我在WPF中有一个TextBlock,并将该TextBlock的文本属性绑定到多依赖属性。我想绑定这些依赖属性conditional。换句话说,我想每次都将一些依赖属性绑定到TextBlock对象的文本属性。我该怎么办?

第1版:

我的TextBlock在下面。我通过绑定依赖项属性的调查值来计算此文本块的文本属性。并希望通过更改每个绑定依赖属性来刷新文本块的文本。一些绑定依赖属性可能是null值,我不想将此依赖属性绑定到我的文本属性。当我调试我的应用程序并且依赖项属性为null时,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>

嗨,在你的转换器中试试这个

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;
 }

我希望你的一切都在发挥作用。我希望这会有所帮助。

相关内容

  • 没有找到相关文章

最新更新