Loading xamls (UserControls) without adding corresponding C++ classes
Posted: 17 Nov 2021, 17:35
As I observed in the sample projects, we need to create C++ view classes to corresponding UserControls. The C++ class is only loading the xaml, and I found it cumbersome. I understand that it is necessary for Noesis when parsing the XAML markups. But can we have a solution where we do not need to do add these c++ classes?
I come-up with a solution where we need such XAML markup,
<view:UserAvatar />
I could create a custom control to load the xaml directly. (view:XamlLoaderControl is a Custom Control)
<view:XamlLoaderControl Source="/BlendProj;component/views/user_avatar.xaml" />
This way I wouldn't need to create UserAvatar.h/cpp classes or Noesis registration of these components.
I use Noesis::GUI::LoadXaml in Noesis and Application.LoadComponent in the C# code.
Although such solution works perfectly in Noesis, Blend-runtime, it is sometimes problematic in Blend designtime preview. I think using Application.LoadComponent requires building the project first and it is not reliable. Since we do not have much things to change how Blend is working, I start to consider doing some changes in Noesis.
I can imagine such solution that when Noesis is parsing xaml and when it finds a custom XML Markup (eg. <view:UserAvatar/>) and if it can't find the symbol definition, it can call some callback where we could load the xaml for that control manually (similar to XamlProvider or TextureProvider). This way we wouldn't need to write the c++ class that only loads the xaml. To be able to make this work, we would need to have a mapping between the name of xaml markup to the xaml file. But developer can solve that part the way they want.
Would it be possible to add such feature to the Noesis?
I come-up with a solution where we need such XAML markup,
<view:UserAvatar />
I could create a custom control to load the xaml directly. (view:XamlLoaderControl is a Custom Control)
<view:XamlLoaderControl Source="/BlendProj;component/views/user_avatar.xaml" />
This way I wouldn't need to create UserAvatar.h/cpp classes or Noesis registration of these components.
I use Noesis::GUI::LoadXaml in Noesis and Application.LoadComponent in the C# code.
Although such solution works perfectly in Noesis, Blend-runtime, it is sometimes problematic in Blend designtime preview. I think using Application.LoadComponent requires building the project first and it is not reliable. Since we do not have much things to change how Blend is working, I start to consider doing some changes in Noesis.
I can imagine such solution that when Noesis is parsing xaml and when it finds a custom XML Markup (eg. <view:UserAvatar/>) and if it can't find the symbol definition, it can call some callback where we could load the xaml for that control manually (similar to XamlProvider or TextureProvider). This way we wouldn't need to write the c++ class that only loads the xaml. To be able to make this work, we would need to have a mapping between the name of xaml markup to the xaml file. But developer can solve that part the way they want.
Would it be possible to add such feature to the Noesis?