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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:49:38+00:00 2026-05-16T16:49:38+00:00

Continuing from my last question , I’d like to know how can I bind

  • 0

Continuing from my last question, I’d like to know how can I bind when a button is clicked (can this be done through pure XAML?) – or more simply, how can I do XAML-like binding through C# code?

EDIT: The previous question containing info:

I want to create a listbox that’ll be bound to XPath, relative to the other listbox’s currently selected item.

It’s using XmlDataProvider for the data, and the XML file looks like this:

<Programs>
    <Program name="...">
        <Step name="..."/>
        <Step name="..."/>
    </Program>
    <Program name="another">

    ...

</Programs>

So, the “parent” listbox is listing out all the programs, while “child” shows only Steps from the current Program.
I just need a pointer on the fact what’s such type of binding called.

Thanks in advance.

End of previous question

The question is how can I do a one time bind (I do not want binding to change as soon as user clicks another listbox item) when a button called “Load” is pressed?

  • 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-16T16:49:39+00:00Added an answer on May 16, 2026 at 4:49 pm

    Let’s start with an example where the detail list box does change whenever the user selects an item in the master list box:

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Page.Resources>
        <XmlDataProvider x:Key="Programs">
          <x:XData>
            <Programs xmlns="">
              <Program name="Some program">
                <Step name="Some program step 1"/>
                <Step name="Some program step 2"/>
                <Step name="Some program step 3"/>
                <Step name="Some program step 4"/>
              </Program>
              <Program name="Some other program">
                <Step name="Some other program step 1"/>
                <Step name="Some other program step 2"/>
                <Step name="Some other program step 3"/>
                <Step name="Some other program step 4"/>
              </Program>        
            </Programs>
          </x:XData>
        </XmlDataProvider>
      </Page.Resources>
      <DockPanel>  
        <Label DockPanel.Dock="Top">Programs</Label>
        <ListBox x:Name="Program" DockPanel.Dock="Top" ItemsSource="{Binding Source={StaticResource Programs}, XPath=/Programs/Program}">
          <ListBox.ItemTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding XPath=@name}"/>
            </DataTemplate>
          </ListBox.ItemTemplate>
        </ListBox>
        <Label DockPanel.Dock="Top">Steps</Label>
        <ListBox x:Name="Step" DockPanel.Dock="Top" DataContext="{Binding ElementName=Program, Path=SelectedItem}" ItemsSource="{Binding XPath=Step/@name}"/>
      </DockPanel>
    </Page>
    

    What has to change in order for the detail to change only when the user clicks a button? One thing: the DataContext on the ListBox named Step. You need to use code-behind to do this, but the code is pretty simple:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        if (Program.SelectedItem != null)
        {
            Step.DataContext = Program.SelectedItem;
        }
    }
    

    Edit

    In order for the above to work, you have to change the Step ListBox to:

    <ListBox x:Name="Step" DockPanel.Dock="Top" ItemsSource="{Binding XPath=Step/@name}"/>
    

    That ListBox won’t display anything unless its DataContext is assigned.

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

Sidebar

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.