我正在使用Caliburn.Micro.Contrib的ConductResult激活指挥中的新项目。指挥是Conductor<IScreen>.Collection.OneActive
类型,并且已经有一个项目显示并正常工作。
然而,新项目在激活后未显示。我已经检查过并且指挥的 ActiveItem 设置为该新项目,新项目也已激活。新项目的视图 IsVisible 也设置为true,因此我不明白为什么它不可见。
指挥家的XAML非常简单:
<UserControl x:Class="..."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Path=ActiveItem, Converter={StaticResource objectTypeConverter}}" Margin="5" />
<ItemsControl Grid.Row="1" ItemsSource="{Binding Items}" BorderBrush="Aqua" BorderThickness="10 ">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Converter={StaticResource objectTypeConverter},ConverterParameter=something}" Margin="5" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ContentControl Grid.Row="2" x:Name="ActiveItem" />
</Grid>
</UserControl>
(TextBlock和ItemsControl用于调试目的;它们证明新项目在指挥内进行(即项目集合包含它),新项目设置为ActiveItem)
答案 0 :(得分:0)
就我而言,我使用IoC.Get<IShell>
来访问父视图模型。
默认的引导程序说container.PerRequest<IShell, ShellViewModel>();
这就是为什么我得到了ShellViewModel
类的另一个实例,激活项目就好了,但没有UI正在更新。
一种解决方法是将container.PerRequest
替换为container.Singleton
。
另一个是将IoC.Get<IShell>()
更改为( (IShell)Parent )