使用Prism / RibbonControl进行MultiBinding导致转换器提前启动

时间:2010-09-01 17:57:14

标签: wpf prism ribbon-control

    <inf:WorkspaceContent.Resources>
    <ResourceDictionary>
        <commands:CommandReference x:Key="CompareCommandReference" Command="{Binding CompareCommand}"/>
        <converters:FlowDocumentConverter x:Key="FlowDocConverter"/>
    </ResourceDictionary>
</inf:WorkspaceContent.Resources>

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0.5*"/>
        <ColumnDefinition Width="0.5*"/>
    </Grid.ColumnDefinitions>
    <RichTextBox x:Name="OrigText" Margin="0,0,8,0" d:LayoutOverrides="Width">
        <FlowDocument>
            <Paragraph><Run Text="The fox jumped over the hill. The fox jumped over the mountain."/></Paragraph>
            <Paragraph><Run Text=""/></Paragraph>
        </FlowDocument>
    </RichTextBox>
    <Button x:Name="OrigFileBrowse" HorizontalAlignment="Center" Margin="0,0,8,2.442" Width="75" Content="Browse" Grid.Row="1" d:LayoutOverrides="Height"/>
    <RichTextBox x:Name="ModifiedText" Grid.Column="1" Margin="8,0,0,0">
        <FlowDocument>
            <Paragraph><Run Text="The fox junped over the hill. The fax jumped over the mountain."/></Paragraph>
        </FlowDocument>
    </RichTextBox>
    <Button x:Name="ModifiedFileBrowse" HorizontalAlignment="Center" Width="75" Content="Browse" Grid.Row="1" Grid.Column="1" Margin="0,0,0,2.442" d:LayoutOverrides="Height"/>
    <Button x:Name="Compare" Command="{StaticResource CompareCommandReference}" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75" Content="Compare" Grid.Row="2" Grid.ColumnSpan="2">
        <Button.CommandParameter>
            <MultiBinding Converter="{StaticResource FlowDocConverter}">
                <Binding Path="Document" ElementName="OrigText"/>
                <Binding Path="Document" ElementName="ModifiedText"/>
            </MultiBinding>
        </Button.CommandParameter>
    </Button>
</Grid>

上面是问题的XAML ...我有一个按钮,当点击时通过Prism中的IEventAggregator发布一个事件,传递的视图是上面的内容。然后转换器触发,值看起来合法。但是我希望比较在上面触发compare命令时触发。但是当发生这种情况时,对象[]有2个项目都是空的......不确定是什么导致这个?

1 个答案:

答案 0 :(得分:0)

这是设计的。它将被缓存,因为底层的FlowDocument引用不会更改。解决方案是将项目不是作为简单对象[]返回,而是作为新定义的类型。执行此操作后,执行Compare命令时,值将通过参数返回。