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

  • Home
  • SEARCH
  • 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 6069681
In Process

The Archive Base Latest Questions

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

Initially I had this code in XAML: <CollectionViewSource x:Name=cSource> <CollectionViewSource.Source> <Binding Source={StaticResource NameOfXmlDataProvider} XPath=letter/>

  • 0

Initially I had this code in XAML:

<CollectionViewSource x:Name="cSource">
  <CollectionViewSource.Source>
    <Binding Source="{StaticResource NameOfXmlDataProvider}" XPath="letter"/>
  </CollectionViewSource.Source>
<CollectionViewSource>

But I wanted to keep a binding object in the C# code, to be able to dynamically alter it’s xpath.
Currently I have this code:

CollectionViewSource viewSource = this.FindResource("cSource") as CollectionViewSource;
Binding binding = new Binding( "Source" );
binding.Source = _xmlDataProvider;
binding.XPath = "/new/path/to/nodes";
BindingOperations.SetBinding( viewSource, CollectionViewSource.SourceProperty, binding );

This compiles and doesn’t complain but when called it only leads to an empty list.
I can’t seem to find related examples in the web – most of them deal with the data providers but I want to change the binding.

  • Anybody knows how to fix this?
  • Or is there a better way to do this?
  • Maybe from retrieving the binding object from the collectionview and changing it?
  • 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-23T09:50:55+00:00Added an answer on May 23, 2026 at 9:50 am

    Rather than bind to a static resource in the XAML (yuk) or dynamically change the binding (yukkier), bind to things you can change.

    <CollectionViewSource x:Name="cSource">
      <CollectionViewSource.Source>
        <Binding Source="{Binding MyDataProviderProperty}" XPath="{Binding MyDataXPathProperty}"/>
      </CollectionViewSource.Source>
    <CollectionViewSource>
    

    If you don’t want to go full MVVM, a nice trick is that you can bind your page DataContext to your page’s code-behind class by simply naming the UserControl element of your page and use ElementName to bind the datacontext to it (the only restriction is that the DataContext binding can’t also be on the UserControl (so place it on the first child, like a grid):

    <UserControl x:Class="BindingTests.BindingToSelfExample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400" x:Name="MyViewClass">
        <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding ElementName=MyViewClass}">
            <TextBlock Text="{Binding SomePropertyOfTheCodeBehind}" Width="100" Height="20"/>
        </Grid>
    </UserControl>
    

    Now, so long as you have notify properties on your code behind called MyDataProviderProperty and MyDataXPath, you can change them to your heart’s content.

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

Sidebar

Related Questions

For this assignment I had to create my own string class. I initially wrote
Initially I thought this was going to work, but now I understand it won't
I recently had to re-factor some code from a previous maintainer and initially I
I'm working with a UITableView and a custom UITableViewCell . Initially, this had poor
I've had soooo much trouble getting this code to work properly!!!! It runs fine
I recently wrote a program that used a simple producer/consumer pattern. It initially had
Initially I had a method in our DL that would take in the object
Initially I deployed packages on SQL server but since my machine is not having
I initially designed my system following the s# architecture example outlined in this codeproject
When we initially setup version control we had very limited time and only basic

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.