0

I am a little new to WPF.

I want to use one window for all my content, the content will vary dramatically and the Window.Resources content will need to vary also.

<Window x:Class="NS01.WPF01"
        xmlns:b="clr-namespace:NS01"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
     xmlns:local="clr-namespace:FluidKit.Showcase.ElementFlow"
     xmlns:Controls="clr-namespace:FluidKit.Controls;assembly=FluidKit"
                
        Loaded="Window_Loaded"
        Title="NS01"
     WindowStartupLocation="CenterScreen"
        Width="1280"
        Height="720"
        WindowStyle="ThreeDBorderWindow">

    <Window.Resources>
      ...
    </Window.Resources>
  
    <Grid>
        ...
    </Grid>
  
  </Window>

As an example, I would like to use some third party content like FluidKit's ElementFlow.

There are many good examples of how to dynamically Load UserControls, but nothing on Window in Window. The best I have found is: Changing content dynamically in wpf window

I would like to have multiple *.xaml Files in my project and load content dynamically into the Current Window.

EDIT:

I like WPF Frame, but I can not load and unload Window.Resources:

<Window x:Class="NS01.WPF01"
        xmlns:b="clr-namespace:NS01"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
     xmlns:local="clr-namespace:FluidKit.Showcase.ElementFlow"
     xmlns:Controls="clr-namespace:FluidKit.Controls;assembly=FluidKit"
                
        Loaded="Window_Loaded"
        Title="NS01"
     WindowStartupLocation="CenterScreen"
        Width="1280"
        Height="720"
        WindowStyle="ThreeDBorderWindow">

    <Window.Resources>
      ...
    </Window.Resources>
  
    <Frame Name="ContentHolder" />
  
  </Window>
ContentHolder.Source = new Uri("/XAML/Repository/Page1.xaml", UriKind.Relative);

Just so you know, I have explored:

SolidColorBrush SolidColorBrushRed = new SolidColorBrush(Colors.Red);
this.Resources.Add("RedBrushResource", SolidColorBrushRed);

Is what I am wanting to do possible? Can I load all the required content from a single xaml File?

Thanks.

EDIT:

This is one method, but not really what I was wanting:

<Page x:Class="NS01.XAML.Repository.Page1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:local="clr-namespace:NS01.XAML.Repository"
  mc:Ignorable="d" 
  d:DesignHeight="300" d:DesignWidth="300"
  Title="Page1">

<Grid>

    <TextBlock Text="Welcome" FontSize="18" Foreground="{DynamicResource ResourceKey=textForeColorResource}" Margin="80,32,66,219"/>

</Grid>

</Page>

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:NS01.XAML.Resources">

<SolidColorBrush x:Key="textForeColorResource" Color="Blue"/>

</ResourceDictionary>
ContentHolder.Source = new Uri("/XAML/Repository/Page1.xaml", UriKind.Relative);

ResourceDictionary RD = new ResourceDictionary() 
{ 
Source = new Uri("/NS01;component/XAML/Resources/Page1.xaml", UriKind.RelativeOrAbsolute) 
};

Application.Current.Resources.MergedDictionaries.Add(RD);

Application.Current.Resources.MergedDictionaries.Remove(RD);

foreach (var R in MWindow.Resources)
{
MessageBox.Show(R.ToString());
}
Community
  • 1
  • 1
Rusty Nail
  • 2,692
  • 3
  • 34
  • 55
  • 1
    Are trying to develop something like an app with a MDI form? – Kosala W Sep 16 '16 at 02:20
  • Sort of, its multiple GUInterfaces in the one GUI. I have done it before in Win Forms, just hiding the UI for each. Clumsy and cumbersome, but save a lot of User Headaches. – Rusty Nail Sep 16 '16 at 02:25
  • 1
    You can use [Caliburn micro IConductor](https://caliburnmicro.codeplex.com/wikipage?title=Screens,%20Conductors%20and%20Composition) interface to implement it. – Kosala W Sep 16 '16 at 02:31

0 Answers0