I'm trying to make a modern editor for my game using WPF, a GridSplitter and a DirectX rendered WindowsFormsHostControl. I can draw fine with C++ DirectX routines called from the main C# program, but I'm facing a strange problem. Next is an image of my editor window:
The center area is C++ DirectX rendered one, on the left and right areas I have WPF controls. The left area as you can see is splitted with a WPF GridSplitter.
I can drag without any problems the GridSplitter up and down just before I call the DirectX CreateDevice() function, but when that function is called and DirectX rendering is started I can also drag the GridSplitter but it returns in the original center position after some milliseconds if I make tiny mouse movements, while if I make "big" movements with mouse the GridSplitter moves accordingly (more or less.. but I lost precision and an user would think its really crap).
Its not a machine speed problem, even if I disable rendering (but I continue to have the DirectX device attached to the WindowsFormsHost hwnd) the anomaly persists. It seems that once the DirectX device is created it "eats" events to WPF. Have I forgot something during DirectX or some WPF initialization? There are ways to eliminate this problem?
The only solution I'm thinking now is to close the DirectX device while the user is dragging the GridSplitter and recreate it as the user finishes dragging, but I'm hoping to resolve the problem, not avoiding it! Thank you really a lot for your replies.
Following is the current skeleton of my xaml code, I just removed some (here unuseful) parts, note that in the panel contained in the WindowsFormsHost I add at runtime a WinForms Control (a class I derived from Winforms Control class) from where I take the Window handle and pass it to a C++ routine that calls DirectX CreateDevice() function.
<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>
ccWinFormsPanel
? – legalize