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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:40:05+00:00 2026-05-18T07:40:05+00:00

So I have a list of objects containing a name and number bound to

  • 0

So I have a list of objects containing a name and number bound to a listbox in XAML. The listbox displays the number fine, but I want it to call the phone number using phonecall on click. Here is the onlick code:

    private void taxiListItem_Click(object sender, RoutedEventArgs e)
    {
        Microsoft.Phone.Tasks.PhoneCallTask phonecall = new Microsoft.Phone.Tasks.PhoneCallTask();
        phonecall.PhoneNumber = "213";
        phonecall.Show();
    }

and here is where I define the TaxiCompany object that populates the list.

    public class TaxiCompany {
        public String CoName { get; set; }
        public String Phone { get; set; }
        public TaxiCompany(String coname, String phone) {
            this.CoName = coname;
            this.Phone = phone;

        }
    }

The phone call works fine when I hardcode the number . Now, when I set phonecall.Phonenumber = sender.getPhone() or e.Phone() or any variant of the two, its marked as an undefined method. Am I doing something fundamentally wrong here? I assume object sender or e is the list item being clicked on.

Note: the listbox in the XAML displays both the phone number and address just fine

                   <Button Click="taxiListItem_Click" Width ="436" Height="120">
                        <Button.Content>
                            <StackPanel Orientation="Vertical" Height=" 80">
                            <StackPanel Orientation="Horizontal" Height="40" Width="436">
                                <TextBlock Width="436" FontSize="30" Text= "{Binding CoName}" Height="40"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Height="40" Width="436">
                                <TextBlock Name ="PhoneNo"  Width="300" FontSize="22" Text= "{Binding Phone}" Height="40"/>
                            </StackPanel>

                            </StackPanel>    
                        </Button.Content>
                    </Button>

First time working with C# / Silverlight so any help would be apprecaited.

  • 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-18T07:40:06+00:00Added an answer on May 18, 2026 at 7:40 am

    Try this. The listbox shows the taxi companies and selecting an item in the list causes the phone numbe rot try and be dialed.

    Notice that it’s not necessary to add buttons to the list and that it’s necessary to cast the variables passed to the selection event. (Could also cast the sender to a listbox and then cast the selected item.)

    xaml:

    <ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding TaxiCompanies}" SelectionChanged="MainListBox_SelectionChanged">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical" Height=" 80">
                    <TextBlock Width="436" FontSize="30" Text= "{Binding CoName}" Height="40"/>
                    <TextBlock Name ="PhoneNo"  Width="300" FontSize="22" Text= "{Binding Phone}" Height="40"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    cs:

    // class used for example. Another name would be more appropriate
    public class ViewModel
    {
        public ObservableCollection<TaxiCompany> TaxiCompanies { get; private set; }
    
        public ViewModel()
        {
            TaxiCompanies = new ObservableCollection<TaxiCompany>();
            TaxiCompanies.Add(new TaxiCompany("AAA Cabs", "123-456-789"));
            TaxiCompanies.Add(new TaxiCompany("BBB Taxis", "111234329"));
            TaxiCompanies.Add(new TaxiCompany("CCC Cars", "98765432"));
        }
    }
    
        public MainPage()
        {
            InitializeComponent();
    
            // Set the data context of the listbox control to the sample data
            DataContext = new ViewModel();
    
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
    
        private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var phonecall = new PhoneCallTask();
            phonecall.PhoneNumber = ((TaxiCompany)(((object[])(e.AddedItems))[0])).Phone;
            phonecall.Show();
    
            // Reset selected index to -1 (no selection)
            MainListBox.SelectedIndex = -1;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of objects, each containing an Id, Code and Description. I
I have div containing a list of flash objects. The list is long so
I have IQueryable list of objects of type T which I want to transform
I have a list of objects and I want to reorder them randomly on
I have a list of objects I wish to sort based on a field
I have a list of objects (for the sake of example, let's say 5).
I have a list of objects and I would like to access the objects
I have a list of objects which need to be output 2 items per
I have a list of objects output from ldapsearch as follows: dn: cn=HPOTTER,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn:
I have a list of bean objects passed into my JSP page, and one

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.