Hello everyone, I am a wolf at the end of the desert.
I tried WPF mixed Blazor development today, and it felt good. By the way, I simply shared the tested program: a simple dialogue program developed by WPF mixed Blazor.
Using the technology stack:
Build a WPF + Blazor program
学习WPF + Blazor混合开发的Hello World最好的地方是微软文档:
https://learn.microsoft.com/zh-cn/aspnet/core/blazor/hybrid/tutorials/wpf?view=aspnetcore-7.0
effect
UI使用了Masa Blazor,效果个人感觉不错,如果用WPF实现,要麻烦不少,以下是几个效果截图:
-
- User List Window **
使用了Masa Blazor的列表组件,代码几乎是直接Copy过来的,参考链接Masa Blazor列表:

-
- Chat window **
这个简单,左侧是一个列表,同上面的用户列表类似,只是去掉了上方蓝色的MToolbar和用户的详细描述信息,右侧则是多行文本框显示聊天记录、单行文本框输入即时聊天信息、一个发送按钮(简单描述,不贴代码,后面有仓库链接)。

-
- Open sub-window **
列表的点击事件,使用IEventAggregator发送打开子窗体事件 OpenUserDialogEvent,事件订阅方法执行弹出子窗体操作:

-
- Demonstrate sending messages **
发送消息按钮点击,使用IEventAggregator 发送发送消息事件SendMessageEvent,事件订阅方法接收消息,并追加到各自历史聊天多行文本框展示:

source code
GitHub:https://github.com/dotnet9/WPFBlazorChat
The effect is okay, but I won't explain the code. If you are interested, run and have a look. There are a few points at present and have time to optimize them later. After all, it's almost 2 o'clock in the morning:
Custom forms or implemented in WPF mode
The form is transparent. The Border mouse presses the event to drag the form, and the Close Form button in the upper right corner to close the form. Try again later and use Razor to achieve it.
Prism. DryIoc and IServiceCollection duplicate registration objects for two Ioc containers
本以为搞混合开发挺简单的,实际做才会遇到问题,如果要实现模块化,两种容器可能会处理类似的对象依赖注入,比如
IEventAggregator在Prism中是默认注入了,如果Razor中使用还要注入到IServiceCollection中。
More, I will add later, today is just a try...