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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:24:46+00:00 2026-05-28T03:24:46+00:00

I making a soundboard as an exercise for myself. I want to parse the

  • 0

I making a soundboard as an exercise for myself. I want to parse the URIs from an XML file and bind them to a single mediaelement. I have eight buttons that I want to trigger different audio files. I only have one page so I can’t use NavigationContext.QueryString to pass an attribute id as a querystring to LINQ. How can I change the attribute depending on what button I press?

Here’s the code:

Audio Class:

public class AudioClass
{
    string audio;

    public string Audio 
    {
        get { return audio; }
        set { audio = value; }
    }

}

Code:

public partial class MainPage : PhoneApplicationPage
{
    string name = "C";

    public MainPage()
    {
        InitializeComponent();    
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        XDocument audioPlayer = XDocument.Load("Audio.xml");

        var aani = (from audio in audioPlayer.Descendants("Note")
                    where audio.Attribute("id").Value == name
                    select new AudioClass
                    {
                        Audio = (string)audio.Element("url").Value

                    }).SingleOrDefault();

        player.Source = new Uri(aani.Audio, UriKind.Relative);

        base.OnNavigatedTo(e);
    }

    private void C_Key_Click(object sender, RoutedEventArgs e)
    {
        player.Play();
    }

    private void D_Key_Click(object sender, RoutedEventArgs e)
    {
        player.Play();
    }

And XAML:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="41,-8,-17,8">
        <Button x:Name="C_key" Content="" HorizontalAlignment="Left" Height="220" Margin="8,0,0,8" Style="{StaticResource C}" VerticalAlignment="Bottom" Width="75" Click="C_Key_Click"/>
        <Button x:Name="D_key" Content="" HorizontalAlignment="Left" Height="220" Margin="87,0,0,8" Style="{StaticResource D}" VerticalAlignment="Bottom" Width="75" Click="D_Key_Click"/>
        <Button x:Name="E_key" Content="" HorizontalAlignment="Left" Height="220" Margin="166,0,0,8" Style="{StaticResource E}" VerticalAlignment="Bottom" Width="75" Click="E_Key_Click"/>
        <Button x:Name="F_key" Content="" HorizontalAlignment="Left" Height="220" Margin="245,0,0,8" Style="{StaticResource F}" VerticalAlignment="Bottom" Width="75" d:LayoutOverrides="Width" Click="F_Key_Click"/>
        <Button x:Name="G_key" Content="" Height="220" Margin="324,0,305,8" Style="{StaticResource G}" VerticalAlignment="Bottom" Click="G_Key_Click"/>
        <Button x:Name="A_key" Content="" HorizontalAlignment="Right" Height="220" Margin="0,0,226,8" Style="{StaticResource A}" VerticalAlignment="Bottom" Width="75" Click="A_Key_Click"/>
        <Button x:Name="B_key" Content="" HorizontalAlignment="Right" Height="220" Margin="0,0,147,8" Style="{StaticResource B}" VerticalAlignment="Bottom" Width="75" Click="B_Key_Click"/>
        <Button x:Name="C2_key" Content="" HorizontalAlignment="Right" Height="220" Margin="0,0,68,8" Style="{StaticResource C2}" VerticalAlignment="Bottom" Width="75" Click="C2_Key_Click"/>
        <MediaElement Height="120" HorizontalAlignment="Left" Margin="8,6,0,0" Name="player" VerticalAlignment="Top" Width="160" Source="{Binding Audio}" Volume="1" AutoPlay="False"/>
        </Grid>
  • 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-28T03:24:47+00:00Added an answer on May 28, 2026 at 3:24 am
    1. Extract SetPlayerSource() from OnNavigatedTo().
    2. Use SetPlayerSource() in generic button click event handler.

      protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
      {
          SetPlayerSource();
      
          base.OnNavigatedTo(e);
      }
      
      private void SetPlayerSource()
      {
          XDocument audioPlayer = XDocument.Load("Audio.xml");
      
          var aani = (from audio in audioPlayer.Descendants("Note")
                      where audio.Attribute("id").Value == name
                      select new AudioClass
                      {
                          Audio = (string)audio.Element("url").Value
      
                      }).SingleOrDefault();
      
          player.Source = new Uri(aani.Audio, UriKind.Relative);
      }
      
      private void ButtonKey_Click(object sender, RoutedEventArgs e)
      {
          var buttonName = (sender as Button).Name;
          var underscorePos = buttonName.IndexOf('_');
          name = buttonName.Substring(0, underscorePos);
          SetPlayerSource();
          player.Play();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im making an application where i have to load my database from html file
Making a mobile friendly site, I have a single field and a submit button.
I'm making an Android soundboard. I currently have 12 pages for this specific category.
Making a word document of our network set-up. We have about 7 servers and
making a new jsp and got a mock-up from some analyst. Notice the sections
I'm making a soundboard with sound effects and I'm getting : A first chance
making a multi-language site with codeginiter. I have created two folders. One for french
Making the transition from Vim to gVim, I would like to disable all toolbars
Making a simple program which will generate a multiple choice form. I have an
Making my way through the GAE documents. I have a question I can't find

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.