-
Notifications
You must be signed in to change notification settings - Fork 285
Add wpf islands example #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Need some help figuring how to get the template on the library to work . seems we need a way to specify the XamlMetadaProvider. cc @JesseCol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a side question beyond this PR, but would it be better to start using slnx? https://devblogs.microsoft.com/visualstudio/new-simpler-solution-file-format/
{ | ||
_controller = Microsoft.UI.Dispatching.DispatcherQueueController.CreateOnCurrentThread(); | ||
|
||
var xamlApp = new XamlApp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to just be newed up and abandoned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at other samples yes.
|
||
void MainWindow_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
_winUIControl = new WinUIControlHost(ControlHostElement.ActualHeight, ControlHostElement.ActualWidth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to notify this of size changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the height and width are actually not used.. resize seem to just work when I resize the window.
{ | ||
public CustomListView() | ||
{ | ||
ItemTemplate = Application.Current.Resources["ListViewItemTemplate"] as Microsoft.UI.Xaml.DataTemplate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird, why aren't you just defining CustomListView as a templated control and using a style, then you can just directly specify the item template property as the data template in XAML without this code-behind look-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yap sure can try that, this was more copy what MAUI is doing.
|
||
namespace SimpleWpfXamlIslandApp | ||
{ | ||
internal class XamlApp : Microsoft.UI.Xaml.Application, IXamlMetadataProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a XAML Islands expert, but this seems weird. Should this not just be a file->new winui app but then changed to a not have the output type and manifest? But still just use the regular app.xaml and it's generated partial class over trying to manually do all this? Then the reference to the Resource Dictionary for WinUI and your own ListViewStyles.xaml directly should be possible right over trying to include the xbf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is more of a try to figure out how this should work. I did some commits to try that, see WinUIApp, but that didn t work either, the partial xaml is never parsed since InitializeComponent
is never called. When we initialise
WindowsXamlManager.InitializeForCurrentThread
it "jumps" to on launch method of App.xaml.cs.
WE are doing some talks on the WindowsAppSDK office hours chat to figure out this.
<UseWinUI>true</UseWinUI> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.4654" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the latest CsWinRT not be here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe? Whats CsWinRT ?
var grid = new Microsoft.UI.Xaml.Controls.Grid(); | ||
grid.Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Colors.LightGray); | ||
grid.RowDefinitions.Add(new Microsoft.UI.Xaml.Controls.RowDefinition { Height = new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star) }); | ||
grid.RowDefinitions.Add(new Microsoft.UI.Xaml.Controls.RowDefinition { Height = new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star) }); | ||
|
||
var winUiButton = new MyCustomButton(); | ||
winUiButton.Click += (s, e) => | ||
{ | ||
System.Windows.MessageBox.Show("Hello from WinUI!"); | ||
}; | ||
grid.Children.Add(winUiButton); | ||
|
||
var listView = new CustomListView { | ||
|
||
ItemsSource = new List<string> { "Item 1", "Item 2", "Item 3" }, | ||
}; | ||
|
||
Microsoft.UI.Xaml.Controls.Grid.SetRow(listView, 1); | ||
grid.Children.Add(listView); | ||
|
||
_xamlSource.Content = grid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be nice to just define this in a XAML usercontrol or page and then just instantiate that here to set as the content then doing this in all code-behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yap , will do.
Description
This pull request introduces a new WPF sample application (
SimpleWpfXamlIslandApp
) that demonstrates how to host WinUI 3 controls inside a WPF application using XAML Islands. The solution includes both the WPF host app and a supporting WinUI library (WinUILib
) with custom controls and styles. The most important changes are grouped below:WPF Host Application Setup:
SimpleWpfXamlIslandApp
) with basic WPF setup files (App.xaml
,App.xaml.cs
,MainWindow.xaml
,MainWindow.xaml.cs
,AssemblyInfo.cs
, and project file) to serve as the host for WinUI content. [1] [2] [3] [4] [5] [6]WinUIControlHost
, a customHwndHost
that embeds WinUI controls into the WPF window usingDesktopWindowXamlSource
.XamlApp
class to initialize WinUI resources and styles for the embedded controls.WinUI Library and Custom Controls:
WinUILib
) with its own project file.MyCustomButton
, a custom WinUI button, andCustomListView
, a WinUI list view that uses a custom data template. [1] [2]ListViewStyles.xaml
, defining a data template for the custom list view, which includes the custom button.Solution Structure:
SimpleWpfXamlIsland.sln
) to group the WPF app and WinUI library projects.Target Release
Please specify which release this PR should align with. e.g., 1.0, 1.1, 1.1 Preview 1.
Checklist
Note that /azp run currently isn't working for this repo.