Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WindowsFormsHost中的WPF、GridSplitter和DirectX_C#_C++_Wpf_Directx - Fatal编程技术网

C# WindowsFormsHost中的WPF、GridSplitter和DirectX

C# WindowsFormsHost中的WPF、GridSplitter和DirectX,c#,c++,wpf,directx,C#,C++,Wpf,Directx,我正在尝试使用WPF、GridSplitter和DirectX渲染的WindowsFormsHostControl为我的游戏制作一个现代编辑器。我可以用C++主程序调用C++ DirectX程序,但是我面临一个奇怪的问题。接下来是“我的编辑器”窗口的图像: 中央区域是C++ DirectX渲染的一个,在左右区域我有WPF控件。如您所见,左侧区域使用WPF GridSplitter分割 在调用DirectX CreateDevice()函数之前,我可以毫无问题地上下拖动GridSplitter,

我正在尝试使用WPF、GridSplitter和DirectX渲染的WindowsFormsHostControl为我的游戏制作一个现代编辑器。我可以用C++主程序调用C++ DirectX程序,但是我面临一个奇怪的问题。接下来是“我的编辑器”窗口的图像:

中央区域是C++ DirectX渲染的一个,在左右区域我有WPF控件。如您所见,左侧区域使用WPF GridSplitter分割

在调用DirectX CreateDevice()函数之前,我可以毫无问题地上下拖动GridSplitter,但是当调用该函数并启动DirectX渲染时,我也可以拖动GridSplitter,但如果我进行微小的鼠标移动,它会在几毫秒后返回到原始中心位置,而如果我进行“大”鼠标移动GridSplitter会相应地移动(多多少少……但我失去了精度,用户会认为它真的很糟糕)

这不是机器速度问题,即使我禁用渲染(但我继续将DirectX设备连接到WindowsFormsHost hwnd),异常仍然存在。似乎一旦创建了DirectX设备,它就会将事件“吃掉”到WPF。在DirectX或WPF初始化过程中我是否忘记了什么?有没有办法消除这个问题

我现在想的唯一解决方案是在用户拖动GridSplitter时关闭DirectX设备,并在用户完成拖动后重新创建它,但我希望解决问题,而不是避免它!非常感谢您的回复

以下是我的XAML代码的当前框架,我刚刚删除了一些(这里不有用的)部分,注意在Windows窗体中包含的面板中,在运行时添加WiFrm控件(从WiFrass控件类派生的I类),从窗口取走句柄并传递给调用DirectX CealDeVestice()的C++例程。功能

    <Grid Name="ccgrid1" ClipToBounds="False" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto">

        </RowDefinition>
        <RowDefinition Height="*">

        </RowDefinition>

        <RowDefinition Height="Auto">

        </RowDefinition>

    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition />

       <ColumnDefinition Width="1*" />
    </Grid.ColumnDefinitions>
    <Grid Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <ListBox Grid.Row="0" IsEnabled="True" HorizontalAlignment="Stretch" Name="ccCaratteri" VerticalAlignment="Stretch"
                 HorizontalContentAlignment="Center" VerticalContentAlignment="Stretch" ClipToBounds="False"
                 Background="#FFAD4545" Width="Auto" SelectionChanged="ccCaratteri_SelectionChanged">
            <ListBox.BindingGroup>
                <BindingGroup />
            </ListBox.BindingGroup>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel IsItemsHost="True"
                           Width="{Binding RelativeSource={RelativeSource FindAncestor,
                                AncestorType={x:Type ListBox}},
                                Path=ActualWidth}"/>
                </ItemsPanelTemplate>

            </ListBox.ItemsPanel>
        </ListBox>
        <GridSplitter Grid.Row="1"  Height="10" ResizeDirection="Rows" HorizontalAlignment="Stretch">
            <GridSplitter.Template>
                <ControlTemplate TargetType="{x:Type GridSplitter}">
                    <Grid>
                        <Button Content="⁞" />
                        <Rectangle Fill="#00FFFFFF" />
                    </Grid>
                </ControlTemplate>
            </GridSplitter.Template>
        </GridSplitter>



        <TreeView x:Name="t1" Grid.Row="2" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
                  KeyboardNavigation.TabNavigation="Cycle">

            <TreeViewItem Name="RTBContainer" Header="Global" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" Focusable="False" IsExpanded="True" >
                <Border BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderThickness="1,1,1,0" >
                    <Grid  HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" Content="Kerning" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Padding="0,0,0,0"/>
                        <local:CustomNumericTextbox  Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch"
                        HorizontalContentAlignment="Stretch" BorderThickness="0" CJNumOfVisibleChars="-1" CJRangeValidation="-100,100"
                        CJSigned="True" CJMaxLength="3"></local:CustomNumericTextbox>
                    </Grid>
                </Border>
                <Border BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderThickness="1">
                    <Grid  HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" Content="Leading" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Padding="0,0,0,0" />
                        <local:CustomNumericTextbox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" BorderThickness="0"
                                                    CJNumOfVisibleChars="-1" CJRangeValidation="-100,100" CJSigned="True" CJMaxLength="3"></local:CustomNumericTextbox>
                    </Grid>
                </Border>
            </TreeViewItem>

        </TreeView>
    </Grid>
    <WindowsFormsHost Grid.Row="1" Grid.Column="1" Background="Black" >
        <wf:Panel x:Name="ccWinFormsPanel"/>
            <!--<wf:Button x:Name="ccFormButton" Width="1200"/>-->
        <!--<wf:MaskedTextBox x:Name="ccFormControl" Mask="00/00/0000"/>-->
    </WindowsFormsHost>
    <ScrollViewer Grid.Row="1" Grid.Column="2" VerticalScrollBarVisibility="Visible"  HorizontalScrollBarVisibility="Visible">
        <Canvas Name="ccCanvasBitmap" Height="Auto"  Background="Aquamarine" ClipToBounds="True"   />
    </ScrollViewer>
    <Menu Grid.Row="0" Grid.Column="0" DockPanel.Dock="Top" Grid.ColumnSpan="3" VerticalAlignment="Bottom" Height="21">
        <MenuItem Header="F_ile">
            <MenuItem Header="_New Font..." Name="menuNewFont" Click="menuNewFont_Click"/>
            <MenuItem Header="_Open Font..." Name="menuOpenFont" Click="menuOpenFont_Click"/>
            <MenuItem Header="_Import Image..." Name="menuImportImage" Click="menuImportImage_Click"/>

        </MenuItem>
    </Menu>

    <StatusBar Grid.Row="2" Grid.ColumnSpan="3" Height="auto">
        <Label>Zoom</Label>
        <ComboBox Name="ccZoom" SelectionChanged="ccZoom_SelectionChanged" x:FieldModifier="public">

        </ComboBox>
    </StatusBar>
</Grid>

快速移动

这似乎是一个众所周知的WPF GridSplitter问题,在我调用DirectX CreateDevice()函数后出现了一些未知的动机,以下讨论帮助了我:


我当前的解决方法是将GridSplitter DragIncrement值设置为更大的值20。虽然我对自己在这件事上浪费了这么多时间感到非常气愤(感谢Microsoft…),但这种变通方法似乎是一个很好的折衷办法。

这似乎是一个众所周知的WPF GridSplitter问题,对于我的一些未知动机,在调用DirectX CreateDevice()函数后,它出现了,这是帮助我的讨论:


我当前的解决方法是将GridSplitter DragIncrement值设置为更大的值20。虽然我对自己在这件事上浪费的时间感到非常愤怒(感谢Microsoft…),但这种解决办法似乎是一个很好的折衷办法。

WPF控件和DirectX设备窗口之间的窗口层次结构是什么?@合法化感谢您的回答,我用您询问的信息更新了我的原始问题,请参见上文。那么您的DirectX设备是在
ccWinFormsPanel
上创建的?@合法化设备是在ccWinFormsPanel中包含的Winforms控件类(在运行时添加)中创建的,WPF控件和DirectX设备窗口之间的窗口层次结构是什么?@合法化感谢您的回答,我用您询问的信息更新了我的原始问题,请参见上文。因此,您的DirectX设备是在
ccWinFormsPanel
?@合法化设备是在ccWinFormsPanel中包含的Winforms控件类(在运行时添加)中创建的,