与 Prism/RibbonControl 的多重绑定导致转换器过早触发
<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 发布一个事件,并传入上面的视图。然后转换器启动,并且这些值看起来是合法的。不过,我希望在上面触发比较命令时触发比较。但是当这种情况发生时,object[] 有 2 个项目都是 null...不知道是什么原因导致的?
<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>
Above is the XAML for the problem...I have a button which when clicked publishes an event via IEventAggregator in Prism, with the View passed in which is what is above. The converter then fires, and the values look legit. However I want the comparison to fire at the moment the compare command is fired above. But when that happens the object[] has 2 items which are both null...not sure what is causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是设计使然。由于底层 FlowDocument 引用不会更改,因此它将被缓存。解决方案不是将项目作为简单的 object[] 返回,而是作为新定义的类型返回。一旦执行此操作,执行比较命令时,值将通过参数返回。
This is by design. It will be cached since the underlying FlowDocument reference does not change. The solution is return the items not as a simple object[] but as a newly defined type. Once you do this the values will come back via the arguments when the Compare command is executed.