0

我有一个TextBlockinWPF并将 text 属性绑定TextBlock到多依赖属性。我想有条件地绑定这些依赖属性。换句话说,我想每次将一些依赖属性绑定到TextBlock对象的文本属性。我能怎么做?

编辑1:

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

1 回答 1

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

我希望您的所有绑定都有效。我希望这会有所帮助。

于 2012-07-15T04:35:49.893 回答