Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1031303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:54:23+00:00 2026-05-16T13:54:23+00:00

I got a problem. I added a frame in the window xaml to load

  • 0

I got a problem. I added a frame in the window xaml to load pages in. I can directly load a page into frame with Source tag of the frame. It works. I need to use the code in C# to refer to the link from listbox menu a poplulate an apropriate link when an listbox item is selected. My problem is that I cannot refer the frame in C# code, it just cannot be seen.
I defined the frame with x:Name=”ContentFrame”. When I refer to in in C#, Intellisense tells that “The name “ContentFrame” does not exist in the current context”. What I am doing wrong? I am lost here. Any ideas are highly appreciated.
Here is the code:

XAML:

<Frame x:Name="ContentFrame" JournalOwnership="OwnsJournal" NavigationUIVisibility="Hidden" Grid.Column="2" </Frame>

C#

private void SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
    ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
    string itemName = lbi.Content.ToString();
    if ( Nav_ListBox.SelectedItem.Equals("Page1" ) )
    {
        ContentFrame.Source = new Uri("Pages/Page1.xaml", UriKind.Relative);
        Canvas_Frame.NavigationUIVisibility = NavigationUIVisibility.Hidden;
    }
}

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T13:54:24+00:00Added an answer on May 16, 2026 at 1:54 pm

    You did it almost right. The only problem is the binding to the selected item. Since the Source property of the frame is of type Uri, and has no dynamic converter, you need an own converter, which does the job:

    public class UriConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            XmlElement element = value as XmlElement;
    
            if (element != null)
            {
                string uriSource = element.SelectSingleNode("source").InnerText;
                return new Uri(uriSource, UriKind.Relative);
            }
            else
                return null;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    You now bind the selected item directly with no xpath and the converter extracts the uri string and builds an Uri object. Here is the fully working xaml (no code behind, except the converter):

    <Window x:Class="FrameTest.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:FrameTest"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <DataTemplate x:Key="pageTemplate" >
                <StackPanel Orientation="Horizontal" >
                    <TextBlock Text="{Binding XPath=name}" FontSize="14"
                               VerticalAlignment="Center" Margin="4" />
                </StackPanel>
            </DataTemplate>
    
            <XmlDataProvider x:Key="PagesData" XPath="Pages">
                <x:XData>
                    <Pages xmlns="">
                        <page id="page01">
                            <name>Page 1</name>
                            <source>Pages/Page1.xaml</source>
                        </page>
                        <page id="page02">
                            <name>Page 2</name>
                            <source>Pages/Page2.xaml</source>
                        </page>
                    </Pages>
    
                </x:XData>
            </XmlDataProvider>
    
            <local:UriConverter x:Key="UriConverter" />
        </Window.Resources>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
    
            <ListBox x:Name="Nav_ListBox" Grid.Column="0" 
                     VerticalAlignment="Top" 
                     TextBlock.Foreground="Black"
                     ItemTemplate="{DynamicResource pageTemplate}"
                     ItemsSource="{Binding  Source={StaticResource PagesData},
                                   XPath=page}"/>
    
            <Frame NavigationUIVisibility="Hidden"  
                   JournalOwnership="OwnsJournal" Grid.Column="1" 
                   Source="{Binding ElementName=Nav_ListBox, Path=SelectedItem,
                                    Converter={StaticResource UriConverter}}"/>
    
        </Grid>
    </Window>
    

    The pages have to be in the pages folder of the same directory of the window of course. In my example, I had two pages with a TextBlock “I am Page1/Page2”.

    Hope i could help you 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem with one of the pages within a website. This page
I've got the following problem: My Flashlight app works fine on my Samsung Galaxy
I got a problem of linking an OpenSSL library into an existing project. Where
I have got a problem with my JSF application. On a page there's a
I got a problem with JQuery in IE. The code works perfectly in firefox.
I got a Problem with the Facebook Login on my page. First I tried
I'm trying to make a appcache file but got some problems... I've added the
i got problem with my code and hopefully someone able to figure it out.
I got problem with sending data in Android using httpPost. I found some example,
I've got problem with DirectX in C#. I want to draw some lines. Firstly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.