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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:59:59+00:00 2026-05-29T16:59:59+00:00

I have a listbox to which I parse info from an XML file. I

  • 0

I have a listbox to which I parse info from an XML file. I created a custom user control for my ListBoxItems which comprises of a checkbox and a textblock to hold people’s names. My problem is that I can’t access and control the controls of the custom ListBoxItem user control in code. I don’t know how to access them. I want to the click event of a button to remove the names which were not checked and save the ones which were checked to a file in IsolatedStorage. I haven’t yet worked on saving the data because I want to get the basic “selected checkbox identification” working first. Could you help me out?

Here’s the code:

    public partial class OppilasLista : PhoneApplicationPage

    {
        XDocument lista = XDocument.Load("NykyisetKurssit.xml");
        XDocument oppilasInfo = XDocument.Load("Oppilaat.xml");
        string id = string.Empty;

        public OppilasLista()
        {
            InitializeComponent();

        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.TryGetValue("id", out id))
            {

                var ryhma = (from ryhmaInfo in lista.Descendants("Kurssi")
                             where ryhmaInfo.Attribute("id").Value == id
                             select new Kurssit
                             {
                                 RyhmanNimi = (string)ryhmaInfo.Element("tunnus").Value

                             }).FirstOrDefault();

                PageTitle.Text = ryhma.RyhmanNimi;

                var oppilas = (from oppilaat in oppilasInfo.Descendants("Oppilas")
                               where oppilaat.Attribute("ryhma").Value == id
                               select new Kurssit
                               {
                                   OppilaanNimi = (string)oppilaat.Element("nimi").Value
                               });

                oppilaidenLista.ItemsSource = oppilas;

            }
            base.OnNavigatedTo(e);
        }

        private void Tallenna_Button_Click(object sender, RoutedEventArgs e)
        {

        }

    }

AND XAML

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="LÄSNÄOLOT" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="{Binding RyhmanNimi}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox ItemsSource="{Binding}" x:Name="oppilaidenLista" Margin="0,0" Height="500" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <local:ListboxItem />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <Button Content="Tallenna" Height="72" HorizontalAlignment="Left" Margin="12,506,0,0" Name="tallennaButton" VerticalAlignment="Top" Width="438" Click="Tallenna_Button_Click" />
        </Grid>
    </Grid>

AND Custom ListBoxItem control

    <Grid x:Name="LayoutRoot">
        <CheckBox Height="72" HorizontalAlignment="Left" Margin="0,7,0,0" Name="checkBox" VerticalAlignment="Top" />
        <TextBlock Height="55" HorizontalAlignment="Left" Margin="74,12,0,0" Name="studentName" Text= "{Binding OppilaanNimi}" VerticalAlignment="Top" Width="394" FontSize="40" />
    </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-29T17:00:00+00:00Added an answer on May 29, 2026 at 5:00 pm

    I’d suggest that you bind your ListBox to a collection of items which have a boolean property you can bind the CheckBox‘s IsChecked property to. Something along the lines of;

    public class Kurssit : INotifyPropertyChanged {
      private string _Oppilaanimi;
      private bool _IsChecked;
    
      public string OppilaanNimi {
        get { return _Oppilaanimi; }
        set {
          if (_Oppilaanimi != value) {
            _Oppilaanimi = value;
            PropertyChanged(this, new PropertyChangedEventArgs("OppilaanNimi"));
          }
      }
    
      public bool IsChecked {
        get { return _IsChecked ; }
        set {
          if (_IsChecked != value) {
            _IsChecked = value;
            PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
          }
      }
    
      public event PropertyChangedEventHandler PropertyChanged;
    }
    

    When you create these items in your LINQ statement store them in a member variable, say, private ObservableCollection<Kurssit> _Kurssit.

    And then bind your ListBox to this member variable;

    oppilaidenLista.ItemsSource = _Kurssit;
    

    Then change your custom ListBoxItem control to be more like;

    <Grid x:Name="LayoutRoot">
        <CheckBox IsChecked="{Binding IsChecked}" Height="72" HorizontalAlignment="Left" Margin="0,7,0,0" Name="checkBox" VerticalAlignment="Top" />
        <TextBlock Height="55" HorizontalAlignment="Left" Margin="74,12,0,0" Name="studentName" Text= "{Binding OppilaanNimi}" VerticalAlignment="Top" Width="394" FontSize="40" />
    </Grid>
    

    Then in your button’s click handler;

    private void Tallenna_Button_Click(object sender, RoutedEventArgs e)
    {
      List<Kurssit> selected = _Kurssit.Where(x => x.IsSelected == true).ToList()
      // You can now operate manipulate this sublist as needed
      // ie. Save this subset of items to IsolatedStorage
      //     Or remove the items from the original _Kurssit collection... whatever :)
    }
    

    Note: Because the member variable you’re binding too in this example is of type ObservableCollection{T} calling Add(), Remove(), et al, will raise events and the ListBox will respond to these adding / removing the UI controls for those items as necessary.

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

Sidebar

Related Questions

I have a Silverlight 2.0 listbox which reads in data from a custom list
I have a ListBox which is populated from a collection of ViewModels, which uses
I have listbox in which I am dynamically showing the pre selected checkboxes from
I have a listbox in which I am displaying the records from the database.
I have a listbox which populated from using a datatable. I have a Add
I am trying to read a xml file from the web and parse it
in my Silverlight 4 application, I have a listbox for which I created a
I have an asp:listbox which I populate from a database. I am however trying
I have a WPF ListBox which contains a CheckBox as follow: <ListBox x:Name=MyListBox Grid.Row=1
I have a ListBox which is bound to my custom class ObservableCollection<FieldPropertyItem> _fieldOrderCollection`; internal

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.