-1

New to WPF, trying to move back and forth between various UserControls that I've made.

They're defined in separate files, say f1.xaml f2 f3 f4, and then I made a master view.

Can I import f1 and/or f2 into master, and then use them with some logic to move between them (https://rachel53461.wordpress.com/2011/05/28/switching-between-viewsusercontrols-using-mvvm/)? In that article, the DataTemplates are all inlined.

Is my initial assumption flawed, and I actually need to inline all my views into one massive file?

If I can use external files, how do I import an external XAML UserControl into another XAML?

Tutorial links welcome! Edit, post-solve

Posting a couple other tutorial links that helped me out:

Ben
  • 54,723
  • 49
  • 178
  • 224
  • Yes, you can - and the Wordpress article you linked to explains how with a demonstration too. Why do you think you need to ask here? – Dai Feb 09 '18 at 00:46
  • @Dai - cheers, thanks - yes, it shows how to switch between them, but I'm confused how to get them coordinated into the same place. Do I import them or add a `ResourceDictionary` or something? – Ben Feb 09 '18 at 00:47
  • You don't need to "import" or "include" them, just name them as XAML elements using the typenames you gave them, e.g. ` `. Note you'll need an XML namespace prefix, often `local:` or some other value you declared in your `xmlns`. – Dai Feb 09 '18 at 00:50
  • Oh cool! Sounds like that's what I was missing, maybe. Going to try now. – Ben Feb 09 '18 at 00:50
  • @Dai - Yep, that worked, thank you - I can accept as a solution if you want to write up? Also interested in what that concept is called, I'm not sure of the terminology surrounding this. – Ben Feb 09 '18 at 00:54

1 Answers1

2

You don't need to "import" or "include" them, just name them as XAML elements using the typenames you gave them.

For example:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:YourUserControlNamespace"
>
    <StackPanel>
        <local:MyUserControlF1 />
    </StackPanel>
</Window>

Note you'll need an XML namespace prefix, often local: or some other value you declared in your xmlns

Dai
  • 141,631
  • 28
  • 261
  • 374