WPF设计器开始流程

时间:2018-11-26 10:35:39

标签: c# .net wpf directx

我正在做一个Direct3d12应用程序,我想在其中编写编辑器。该应用程序是C ++,但编辑器是使用WPF完成的,我从中将HWND发送到进程,然后该进程在WindowsFormsHost面板上创建交换链。我正在自定义控件构造函数中启动该过程,出于某些时髦的原因,它启动了进程,该进程锁定了exe。在真正运行WPF应用之前,如何停止设计人员运行该过程?

public partial class RenderWindow : UserControl
{
    Process AberrationEngine = new Process();
    public RenderWindow()
    {
        InitializeComponent();

    }

    private void UserControl_Unloaded(object sender, RoutedEventArgs e)
    {
        if (!AberrationEngine.HasExited)
        {
            AberrationEngine.Kill();
        }
    }

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        IntPtr HWND = RenderWindowBase.Handle;

        AberrationEngine.StartInfo.FileName = @"C:\Users\nagylas\Desktop\AberrationEngineNextGen\x64\Release\AberrationEngine.exe";
        AberrationEngine.StartInfo.Arguments = "--editor --handle " + HWND.ToString();
        AberrationEngine.StartInfo.UseShellExecute = false;
        AberrationEngine.StartInfo.WorkingDirectory = @"C:\Users\nagylas\Desktop\AberrationEngineNextGen\AberrationEngine";
        AberrationEngine.Start();
    }
}

和XAML

<Window x:Class="AberrationEditor.MainWindow"
    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:AberrationEditor"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
    xmlns:vs2013="clr-namespace:AvalonDock.Themes.VS2013;assembly=AvalonDock.Themes.VS2013"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:brcr="clr-namespace:AberrationEditor.CustomControls"
    mc:Ignorable="d"
    Title="MainWindow" Height="900" Width="1600" Background="#FF2D2D30">
<Window.Resources>
    <Style TargetType="MenuItem">
        <Setter Property="Background" Value="#FF2D2D30" />
        <Setter Property="BorderBrush" Value="#FF2D2D30" />
        <Setter Property="Foreground" Value="LightGray" />
        <Setter Property="BorderThickness" Value="0" />
    </Style>

    <Style TargetType="Separator" x:Key="{x:Static MenuItem.SeparatorStyleKey}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Separator">
                    <Border Background="#FF888888" Height="1" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <StackPanel Orientation="Horizontal">
        <Menu>
            <MenuItem Header="_File">
                <MenuItem Header="_New" />
                <Separator />
                <MenuItem Header="_Exit" />
            </MenuItem>
            <MenuItem Header="_View">
                <MenuItem Header="_New" />
            </MenuItem>
        </Menu>
    </StackPanel>
    <xcad:DockingManager Grid.Row="1" AllowMixedOrientation="True" BorderBrush="Black" BorderThickness="1">
        <xcad:DockingManager.Theme>
            <vs2013:Vs2013DarkTheme/>
        </xcad:DockingManager.Theme>
        <xcad:DockingManager.DocumentHeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Image Source="{Binding IconSource}" Margin="0,0,4,0"/>
                    <TextBlock Text="{Binding Title}" />
                </StackPanel>
            </DataTemplate>
        </xcad:DockingManager.DocumentHeaderTemplate>
        <xcad:LayoutRoot x:Name="_layoutRoot">
            <xcad:LayoutPanel Orientation="Horizontal">
                <xcad:LayoutDocumentPaneGroup >
                    <xcad:LayoutDocumentPane>
                        <xcad:LayoutDocument ContentId="document1" Title="Document 1">
                            <TextBox Text="Document 1 Content" AcceptsReturn="True"/>
                        </xcad:LayoutDocument>
                        <xcad:LayoutDocument ContentId="document2" Title="Document 2">
                            <brcr:RenderWindow></brcr:RenderWindow>
                        </xcad:LayoutDocument>
                    </xcad:LayoutDocumentPane>
                </xcad:LayoutDocumentPaneGroup >
            </xcad:LayoutPanel>
        </xcad:LayoutRoot>
    </xcad:DockingManager>
</Grid>

1 个答案:

答案 0 :(得分:0)

您可能应该检查它是否是一种设计模式。 您可以使用DesignerProperties.GetIsInDesignMode函数来做到这一点。

Documentation

因此,基本上是这样的:

if (!DesignerProperties.GetIsInDesignMode(this))
{
    //your code running the process
}