1

我正在使用 Caliburn.Micro.Contrib 的ConductResult激活导体中的新项目。导体是 类型Conductor<IScreen>.Collection.OneActive,并且已经有一个项目显示并正常工作。

但是,新项目在激活后不会显示。我已经检查过了,指挥的ActiveItem设置为那个新项目,新项目也被激活了。View的新项目的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 用于调试目的;它们证明新项目是在导体内进行的(即 Items 集合包含它)并且新项目设置为 ActiveItem)

4

1 回答 1

0

就我而言,我IoC.Get<IShell>用来访问父视图模型。

默认引导程序说container.PerRequest<IShell, ShellViewModel>(); 这就是为什么我得到了我的ShellViewModel类的另一个实例,很好地激活了该项目,但没有更新 UI。

一种解决方法是替换container.PerRequestcontainer.Singleton. 另一种是IoC.Get<IShell>()改成( (IShell)Parent )

于 2016-12-22T07:57:46.517 回答