You can load a dictionary xaml file by calling Noesis::GUI::LoadXaml(), and set that dictionary as the Resources of any FrameworkElement in the UI tree.
Ptr<Noesis::ResourceDictionary> dictA = Noesis::GUI::LoadXaml<Noesis::ResourceDictionary>("DictA.xaml");
rootElement->SetResources(dictA);
If you are building your application using MVVM pattern, you can create an interactivity action that encapsulates that code:
class SetResourcesAction: public NoesisApp::TriggerActionT<Noesis::FrameworkElement>
{
public:
const Noesis::Uri& GetSource() const { return GetValue<Noesis::Uri>(SourceProperty); }
void SetSource(const Noesis::Uri& value) { SetValue<Noesis::Uri>(SourceProperty, value); }
static const Noesis::DependencyProperty* SourceProperty;
private:
Noesis::Ptr<Noesis::Freezable> CreateInstanceCore() const override
{
return Noesis::MakePtr<SetResourcesAction>();
}
void Invoke(Noesis::BaseComponent* parameter) override
{
Noesis::FrameworkElement* element = GetAssociatedObject();
element->SetResources(mResources);
}
static void OnSourceChanged(Noesis::DependencyObject* d,
const Noesis::DependencyPropertyChangedEventArgs& e)
{
SetResourcesAction* action = (SetResourcesAction*)d;
const Uri& source = *((const Uri*)e.newValue);
action->mResources = Noesis::GUI::LoadXaml<Noesis::ResourceDictionary>(source.Get());
}
Noesis::Ptr<Noesis::ResourceDictionary> mResources;
NS_IMPLEMENT_INLINE_REFLECTION(SetResourcesAction,
NoesisApp::TriggerActionT<Noesis::FrameworkElement>)
{
NsMeta<Noesis::TypeId>("MyNamespace.SetResourcesAction");
Noesis::DependencyData* data =
NsMeta<Noesis::DependencyData>(Noesis::TypeOf<SetResourcesAction>());
data->RegisterProperty<Noesis::Uri>(SourceProperty, "Source",
Noesis::PropertyMetadata::Create(Noesis::Uri(""), &OnSourceChanged));
}
};
const Noesis::DependencyProperty* SetResourcesAction::SourceProperty;
So you can reuse it in the xaml:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:local="clr-namespace:MyNamespace">
<Grid x:Name="LayoutRoot">
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding IsBlue}" Value="True">
<local:SetResourcesAction Source="BlueResources.xaml" />
</ei:DataTrigger>
<ei:DataTrigger Binding="{Binding IsRed}" Value="True">
<local:SetResourcesAction Source="RedResources.xaml" />
</ei:DataTrigger>
</i:Interaction.Triggers>
...
</Grid>
</UserControl>
Hope this helps.