Не могу использовать windowManager.ShowWindow () с Caliburn.Micro - PullRequest
0 голосов
/ 07 ноября 2019

В настоящее время я разрабатываю плагин для Revit (программное обеспечение BIM) и пытаюсь использовать WPF и Caliburn.Micro для отображения окна / диалогового окна при нажатии кнопки плагина.

Как и в документации, у меня есть загрузчик:

public class Bootstrapper : BootstrapperBase
{

    public Bootstrapper()
    {
        Initialize();
    }

    protected override void OnStartup(object sender, StartupEventArgs e)
    {
        DisplayRootViewFor<LocationPopupViewModel>();
    }
}
}

Простое тестирование ViewModel:

namespace ExternalForms.ViewModels
{

public class LocationPopupViewModel : Screen
{
    private int _horizontalLength;
    private int _verticalLength;

    public int HorizontalLength
    {
        get 
        { 
            return _horizontalLength; 
        }
        set 
        { 
            _horizontalLength = value;
            NotifyOfPropertyChange(() => HorizontalLength);
        }
    }

    public int VerticalLength
    {
        get 
        { 
            return _verticalLength; 
        }
        set 
        { 
            _verticalLength = value;
            NotifyOfPropertyChange(() => VerticalLength);
        }
    }
}
}

И, конечно, окно, которое я хочу показать:

<Window x:Class="ExternalForms.Views.LocationPopupView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:ExternalForms.Views"
    mc:Ignorable="d" WindowStartupLocation="CenterScreen"
    ResizeMode="CanResizeWithGrip"
    Title="gebied" Height="300" Width="410"
    FontSize="16">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="20"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="20"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="20"/>
    </Grid.RowDefinitions>


    <!--Row 1-->
    <TextBlock Text="Stel xxx in" FontWeight="DemiBold" Grid.Column="1" Grid.Row="1" FontSize="18"/>

    <!--Row 2-->
    <StackPanel Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Width="360" Margin="0, 0, 0, 20">
        <TextBlock TextWrapping="Wrap">
            Let op dat het gebied een maximale horizontale en verticale lengte mag hebben van 1 kilometer.
        </TextBlock>
    </StackPanel>


    <!--Row 3-->
    <TextBlock Text="Horizontaal" Grid.Column="1" Grid.Row="3"/>

    <!--Row 4-->
    <TextBox x:Name="HorizontalLength" Grid.Row="4" Grid.Column="1" MinWidth="100"/>


    <!--Row 5-->
    <TextBlock Text="Verticaal" Grid.Column="1" Grid.Row="5"/>

    <!--Row 6-->
    <TextBox x:Name="VerticalLength" Grid.Row="6" Grid.Column="1" MinWidth="100"/>


    <!--Row 7-->
    <StackPanel Orientation="Horizontal" Grid.Row="7" Grid.Column="1" Margin="0, 20, 0, 0" Grid.ColumnSpan="2" HorizontalAlignment="Right">
        <Button x:Name="SubmitDimensions" IsDefault="True" Width="100" Height="30">OK</Button>
        <Button IsCancel="True" IsDefault="True" Width="100" Height="30">Cancel</Button>
    </StackPanel>

</Grid>

Функция, которая пытается показать окно:

        private void SetBoundingBox()
    {
        IWindowManager windowManager = new WindowManager();

        LocationPopupView locationPopup = new LocationPopupView();

        windowManager.ShowWindow(locationPopup, null, null);

    }

Но когда я пытаюсь открыть диалоговое окно в Revit, появляется окно с ошибкой: enter image description here

ОБНОВЛЕНИЕ: Моя текущая структура проекта выглядит следующим образом: enter image description here

Сборка "UI" заботитсявсех внутренних элементов пользовательского интерфейса в Revit (таким образом, кнопки в Revit, хотя в настоящее время есть только один).

Текущая кнопка в Revit вызывает сборку «Get3DBAG», которая выполняет некоторые задачи и в конечном итоге вызываетСборка "Location", которая вызывает метод Windowmanager.showwindow () для представлений WPF, которыйв сборке «Внешние формы».

1 Ответ

0 голосов
/ 08 ноября 2019

Ваша проблема заключается в следующей строке.

LocationPopupView locationPopup = new LocationPopupView();

Вы пытаетесь инициализировать экземпляр View, а не ViewModel. Вам следует заменить это следующим.

LocationPopupViewModel locationPopup = new LocationPopupViewModel();

Caliburn Micro самостоятельно разрешит соответствующий вид, используя соглашение об именах .

Обновление: на основе комментариев

Из вашего комментария похоже, что ваши View / ViewModels находятся в другой сборке. В этом сценарии необходимо убедиться, что сборка включена, пока Caliburn Micro выполняет поиск видов. Вы можете сделать это, переопределив метод SelectAssemblies в Bootstrapper.

    protected override IEnumerable<Assembly> SelectAssemblies()
    {
        return new[] 
       {
           Assembly.GetExecutingAssembly()
          // Ensure your external assembly is included.
       };
    }

Вам также будет интересно прочитать подробнее Пользовательские соглашения с использованием Caliburn Micro

...