none
MultiBinding绑定父控件的附加属性问题 RRS feed

  • 问题

  • 我有一个父Usercontrol,定义了一个附加属性IsBelongRootDocument,我在子UserControl里这么用能成功,如代码:

    <TextBlock Text="OK" Grid.Column="0" Visibility="{Binding Path=IsBelongRootDocument, 
                                            RelativeSource={RelativeSource FindAncestor, AncestorType=my1:ViewDocumentImagesControl, AncestorLevel=1}, Converter={StaticResource BoolTrueToVisibleOrHidden1}}"></TextBlock>

    这样子是能控制TextBlock的Visibility属性的,但是我把他绑定到一个MultiBinding里,用一个Converter来控制就会出错,不知道是什么原因

    如:

      <TextBlock Grid.Column="3"  FontSize="14" FontWeight="Black" HorizontalAlignment="Right">
                                                HorizontalAlignment="Left" >
                                            <TextBlock.Text> 
                                                <MultiBinding Converter="{StaticResource ImageIndexShowInDocument1}"> 
                                                  <Binding Path="IndexInDocument" /> 
                                                  <Binding Path="IndexInBatch" /> 
                                                  <Binding Path="IsBelongRootDocument" RelativeSource="{RelativeSource RelativeSource FindAncestor, AncestorType=my1:ViewDocumentImagesControl, AncestorLevel=1}" /> 
                                                  <Binding Path="IsBelongUnarchivedDocument" RelativeSource="{RelativeSource RelativeSource FindAncestor, AncestorType=my1:ViewDocumentImagesControl, AncestorLevel=1}" /> 
                                                </MultiBinding> 
                                              </TextBlock.Text>
                                        </TextBlock>

    望高人指点一二,非常感谢


    程序人生

    2013年8月27日 2:17

答案

  • 您好,

    根据您的描述和代码,我做了一些测试,您的第二段代码中最后两个绑定中的 RelativeSource 可能有误

    请尝试以下代码:

    <MultiBinding Converter="{StaticResource ImageIndexShowInDocument1}">
                        <Binding Path="IndexInDocument" />
                        <Binding Path="IndexInBatch" />
                        <Binding Path="IsBelongRootDocument" RelativeSource="{RelativeSource FindAncestor, AncestorType=my1:ViewDocumentImagesControl, AncestorLevel=1}" />
                        <Binding Path="IsBelongUnarchivedDocument" RelativeSource="{RelativeSource FindAncestor, AncestorType=my1:ViewDocumentImagesControl, AncestorLevel=1}" />
                    </MultiBinding>

    请阅读以下参考资料:

    #RelativeSource MarkupExtension
    http://msdn.microsoft.com/zh-cn/library/ms743599.aspx


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年8月28日 5:14
    版主

全部回复

  • 您好,

    根据您的描述和代码,我做了一些测试,您的第二段代码中最后两个绑定中的 RelativeSource 可能有误

    请尝试以下代码:

    <MultiBinding Converter="{StaticResource ImageIndexShowInDocument1}">
                        <Binding Path="IndexInDocument" />
                        <Binding Path="IndexInBatch" />
                        <Binding Path="IsBelongRootDocument" RelativeSource="{RelativeSource FindAncestor, AncestorType=my1:ViewDocumentImagesControl, AncestorLevel=1}" />
                        <Binding Path="IsBelongUnarchivedDocument" RelativeSource="{RelativeSource FindAncestor, AncestorType=my1:ViewDocumentImagesControl, AncestorLevel=1}" />
                    </MultiBinding>

    请阅读以下参考资料:

    #RelativeSource MarkupExtension
    http://msdn.microsoft.com/zh-cn/library/ms743599.aspx


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年8月28日 5:14
    版主
  • 嗯,我昨天找到了,谢谢!


    程序人生

    2013年8月28日 6:56