Loading a Xaml (View) and DataContext (ViewModel) at runtime using C# Managed SDK
I was wondering if it is possible to load a specific xaml (View) file with a specific DataContext (ViewModel) class from code using the C# Managed SDK?
If yes, could you provide a quick code example?
I know this is possible using the Unity SDK, you gave a quick code example in this post:
viewtopic.php?t=3115#p16263
However the NoesisView and NoesisXaml classes are specific to the Unity SDK so I am not sure how to do the exact same thing in that post using just the C# Managed SDK.
I don't want to use DataTemplates because that links a specific ViewModel with a specific View. I want to set what XAML file and DataContext classes to use manually (exactly like the Unity SDK).
If yes, could you provide a quick code example?
I know this is possible using the Unity SDK, you gave a quick code example in this post:
viewtopic.php?t=3115#p16263
However the NoesisView and NoesisXaml classes are specific to the Unity SDK so I am not sure how to do the exact same thing in that post using just the C# Managed SDK.
I don't want to use DataTemplates because that links a specific ViewModel with a specific View. I want to set what XAML file and DataContext classes to use manually (exactly like the Unity SDK).
-
sfernandez
Site Admin
- Posts: 3011
- Joined:
Re: Loading a Xaml (View) and DataContext (ViewModel) at runtime using C# Managed SDK
Hi,
In C# SDK you can use the Noesis.GUI.LoadXaml() method to load a xaml. The xaml file should be available through the XamlProvider set at initialization (see Integration sample), or if you are using our application framework, then the xaml file should be embedded into the assembly as we do in the samples included in our SDK.
And to remove it, you will do as explained in the post you mentioned:
Hope this helps.
In C# SDK you can use the Noesis.GUI.LoadXaml() method to load a xaml. The xaml file should be available through the XamlProvider set at initialization (see Integration sample), or if you are using our application framework, then the xaml file should be embedded into the assembly as we do in the samples included in our SDK.
Code: Select all
FrameworkElement LoadContent(Panel container, Uri uri, object vm)
{
FrameworkElement content = Noesis.GUI.LoadXaml(uri) as FrameworkElement;
if (content != null)
{
content.DataContext = vm;
container.Children.Add(content);
}
return content;
}
Code: Select all
void RemoveContent(Panel container, FrameworkElement content)
{
container.Children.Remove(content);
}
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests