Skip to content

Commit

Permalink
Calc: Step 6.1: Prepare for DrawingIsland - Add WpfIslandHost.cs and …
Browse files Browse the repository at this point in the history
…DisplayAreaBorder element
  • Loading branch information
JesseCol committed May 9, 2024
1 parent a4a5871 commit 0eebe88
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="WpfIslandHost.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
4 changes: 3 additions & 1 deletion Samples/Islands/DrawingIsland/CalculatorDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@
Also, make the TextBox borders a little less harsh.
-->
<local:MyTextBox Grid.ColumnSpan="9" x:Name="DisplayBox" Height="30" Margin="5" FontSize="20" BorderBrush="LightGray"/>
<local:MyTextBox Grid.Row="1" Grid.ColumnSpan="3" Grid.RowSpan="5" Margin="5" x:Name="PaperBox" BorderBrush="LightGray"/>
<Border Name="DisplayAreaBorder" Grid.Row="1" Grid.ColumnSpan="3" Grid.RowSpan="5" Margin="5">
<local:MyTextBox x:Name="PaperBox" BorderBrush="LightGray"/>
</Border>
</Grid>

</DockPanel>
Expand Down
34 changes: 34 additions & 0 deletions Samples/Islands/DrawingIsland/CalculatorDemo/WpfIslandHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.UI.Composition;
using Microsoft.UI.Content;
using System.Runtime.InteropServices;
using System.Windows.Interop;

namespace CalculatorDemo
{
internal class WpfIslandHost : HwndHost
{
public WpfIslandHost(Compositor compositor)
{
_compositor = compositor;
}

public DesktopChildSiteBridge DesktopChildSiteBridge { get; private set; }

protected override HandleRef BuildWindowCore(HandleRef hwndParent)
{
DesktopChildSiteBridge = Microsoft.UI.Content.DesktopChildSiteBridge.Create(
_compositor,
new Microsoft.UI.WindowId((ulong)hwndParent.Handle));

return new HandleRef(null, (nint)DesktopChildSiteBridge.WindowId.Value);
}

protected override void DestroyWindowCore(HandleRef hwnd)
{
DesktopChildSiteBridge.Dispose();
DesktopChildSiteBridge = null;
}

Microsoft.UI.Composition.Compositor _compositor;
}
}

0 comments on commit 0eebe88

Please sign in to comment.