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 819505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:19:15+00:00 2026-05-15T02:19:15+00:00

I am loading some XAML pages that I have created that have some data

  • 0

I am loading some XAML pages that I have created that have some data binding in them. However, when I load these XAML files at runtime their data binding no longer works. I’m wondering if it’s some kind of scope or pathing issue or if you just can’t do it.

Here is how I am loading the XAML

using (XmlReader rdr = XmlReader.Create(@".\TwitterModule\TwitterModule.xaml"))
                {
                    Canvas twitter = XamlReader.Load(rdr) as Canvas;
                    contentRoot.Children.Add(twitter);
                }

And here is the my final XAML

    <!--XAML -->    
    <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:LocalTrendsDS="clr-namespace:LocalTrendsDS;assembly=LocalTrendsDS" />
       <Canvas.Resources>
        <XmlDataProvider x:Key="TweetCounter" Source="..\temp\TweetCounter.xml" />
        <LocalTrendsDS:LocalTrends x:Key="LocalTrendsDataSource" />
    </Canvas.Resources> 
        <Canvas x:Name="root" Height="479"  Width="877" 
                    DataContext="{Binding Source={StaticResource TweetCounter}}">
                    <TextBlock x:Name="Number" 
                            Canvas.Left="86.744" LineHeight="122.919" TextAlignment="Right" TextWrapping="Wrap" Width="425.372" 
                            Text="{Binding Mode=OneWay, XPath=/Count}" />
            </Canvas>
<Canvas x:Name="_3a" Height="383" Canvas.Left="1971" Canvas.Top="107" Width="362" 
        DataContext="{Binding Source={StaticResource LocalTrendsDataSource}}">
    <TextBlock x:Name="TrendList" FontSize="16.449"  Canvas.Left="-0.806" LineHeight="16.449" TextAlignment="Left" TextWrapping="Wrap" Canvas.Top="112.155" Height="127.829"><TextBlock.RenderTransform>
                        <MatrixTransform Matrix="2.334,0,0,2.334,0,0"/>
                    </TextBlock.RenderTransform>
                    <Run Foreground="#FF9900EB" FontFamily="Hiruko Alternate" Text="1. "/>
                    <TextBlock Foreground="#FFFFFFFF" FontFamily="Segoe Semibold" Text="{Binding CurrentLocalTrends[0].Value, Mode=Default}"/><LineBreak/>
                    <Run Foreground="#FFDB0072" FontFamily="Hiruko Alternate" Text="2. "/>
                    <TextBlock Foreground="#FFFFFFFF" FontFamily="Segoe Semibold" Text="{Binding CurrentLocalTrends[1].Value, Mode=Default}"/><LineBreak/>
                    <Run Foreground="#FFFF0F1B" FontFamily="Hiruko Alternate" Text="3. "/>
                    <TextBlock Foreground="#FFFFFFFF" FontFamily="Segoe Semibold" Text="{Binding CurrentLocalTrends[2].Value, Mode=Default}"/><LineBreak/>
                    <Run Foreground="#FFFF6E05" FontFamily="Hiruko Alternate" Text="4. "/>
                    <TextBlock Foreground="#FFFFFFFF" FontFamily="Segoe Semibold" Text="{Binding CurrentLocalTrends[3].Value, Mode=Default}"/><LineBreak/>
                    <Run Foreground="#FFFF9F01" FontFamily="Hiruko Alternate" Text="5. "/>
                    <TextBlock Foreground="#FFFFFFFF" FontFamily="Segoe Semibold" Text="{Binding CurrentLocalTrends[4].Value, Mode=Default}"/><LineBreak/>
                </TextBlock>
</Canvas>
    </Canvas>

ANSWER: It was a pathing issue, thanks for your help. I’m able to bind both XmlDataProvider and other Object Data Sources in XAML loaded at runtime. Huge time saver. Build UI in Blend and in the darkness bind them.

  • 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-15T02:19:15+00:00Added an answer on May 15, 2026 at 2:19 am

    It looks like you have a typo in your XAML. Did you mean the following?

    <!--XAML -->
    <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
      <Canvas.Resources>
        <XmlDataProvider x:Key="TweetCounter" Source="\temp\TweetCounter.xml" />
      </Canvas.Resources>
      <Canvas x:Name="root" Height="479"  Width="877"
                  DataContext="{Binding Source={StaticResource TweetCounter}}">
        <TextBlock x:Name="Number"
                Canvas.Left="86.744" LineHeight="122.919" TextAlignment="Right" TextWrapping="Wrap" Width="425.372"
                Text="{Binding Mode=OneWay, XPath=/Count}" />
      </Canvas>
    </Canvas>
    

    Also, FYI, XmlTextReader has been deprecated since .NET 2.0. You should use the following instead:

    using (XmlReader rdr = XmlReader.Create(@".\TwitterModule\TwitterModule.xaml"))
    {
        Canvas twitter = XamlReader.Load(rdr) as Canvas; 
        contentRoot.Children.Add(twitter); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are loading some xaml for an Element at runtime (XamlReader.Load) for some preview
I am loading some text dynamically into a div, but have the problem that
I'm loading in some HTML content like this: $('#scores').load('scores.php #scores'); Note that It is
I have an animated .GIF image that I created with http://ajaxload.info/ and some editing.
I have a series of dynamically created GridViews that I load. Everything works fine
I have a UIScrollView that I am loading some images in. Sometimes I am
I'm loading some swf files at 0 on my stage. They are the pages
I am loading some template files into my application using require.js like so: define(function(require)
I'm loading some feeds and displaying them as links on my site page. When
Summary of the issue: When I am loading some data into my iPhone application

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.