Search code examples
c#wpfuriframeuicontrol

C# WPF Change Frame Source


I have the following folder structure in my project:

enter image description here

In the UserControls folder are "L_Menu.xaml" and "LS_Account.xaml". These are both simple user controls. On the “L_Menu” user control there is a frame control which is empty for now, so the property “Source” is still null.

Now I want to set the source property of the frame to the uri of the “LS_Account” user control by a click event. I use the following uri: "pack://application:,,,/src/Content/UserControls/LS_Account.xaml".

myFrame.Source = new Uri("pack://application:,,,/src/Content/UserControls/LS_Account.xaml", UriKind.Relative);

When executing the code I get the following error message:

"The resource "src/content/usercontrols/src/content/usercontrols/ls_accout.xaml" cannot be found."

Why is the “new” source attached to the source of the “L_Menu” user control?


Solution

  • I know how.

    Just use this.

    yourFrame.Navigate(yourUri);