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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:12:43+00:00 2026-05-31T22:12:43+00:00

hello everybody i have a listbox within which is a datatemplate.Inside it is checkbox,textbox,label…Wat

  • 0

hello everybody i have a listbox within which is a datatemplate.Inside it is checkbox,textbox,label…Wat i want is to get the value of the label wen the checkbox is unchecked? or any alternative as to how to access the label value but only wen the checkbox is unselected…………PLease help me out.
the code is as

<ListBox.ItemTemplate>                                                    
    <DataTemplate>
        <StackPanel Name="sp" Orientation="Horizontal" Margin="3,3,3,3" >                                                       
            <CheckBox Name="chkSubject"   IsChecked="{Binding RelativeSource{RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" VerticalAlignment="Center"  Margin="0,0,4,0" Unchecked="chkSubject_Unchecked">
                <TextBlock FontSize="11" Text="{Binding subject_name}" />
            </CheckBox>
            <Label Name="lbl_idOfSub" Content="{Binding subject_id}" Visibility="Visible">
            </Label>
        </StackPanel>
     </DataTemplate>
</ListBox.ItemTemplate>
  • 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-31T22:12:44+00:00Added an answer on May 31, 2026 at 10:12 pm

    Since you’re using binding on label, I’d go for accessing subject_id from the object the datatemplate is describing. Like this:

    var subjectId = dataBoundItem.subject_id;
    

    That’s the correct way to go with MVVM and bindings.

    UPDATE:

    Here’s the basic MVVM approach to solving this problem. First of all, I’ve cleaned up a bit your listbox declaration and added a trigger that sets IsSelected binding:

        <ListBox ItemsSource="{Binding}">
            <ListBox.Resources>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
                </Style>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Name="sp" Orientation="Horizontal" Margin="3,3,3,3" >
                        <CheckBox Name="chkSubject"   IsChecked="{Binding IsSelected}" VerticalAlignment="Center"  Margin="0,0,4,0" Unchecked="chkSubject_Unchecked_1">
                            <TextBlock FontSize="11" Text="{Binding SubjectName}" />
                        </CheckBox>
                        <Label Name="lbl_idOfSub" Content="{Binding SubjectId}" Visibility="Visible"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    

    Here, whenever value IsSelected on individual ListBoxItem changes, the “IsSelected” binding of the viewModel is changed. Here’s the model:

    public class SelectableItem : INotifyPropertyChanged
    {
        private string _subjectId;
        private bool _isSelected;
        private string _subjectName;
    
        public string SubjectId
        {
            get { return _subjectId; }
            set { _subjectId = value; OnPropertyChanged("SubjectId"); }
        }
    
        public bool IsSelected
        {
            get { return _isSelected; }
            set { _isSelected = value; OnPropertyChanged("IsSelected"); }
        }
    
        public string SubjectName
        {
            get { return _subjectName; }
            set { _subjectName = value; OnPropertyChanged("SubjectName"); }
        }
        // .. INotifyPropertyChangedImplementation
    

    Your IsSelected will be set to true whenever relevant item is selected and to false whenever it is unselected. You may put your code in to the “set” item of the “IsSelected” property and check (value == false) and execute necessary piece of code as you see fit. This would be MVVM approach to the matter.

    Using the event, you can do as follows:

        private void chkSubject_Unchecked_1(object sender, RoutedEventArgs e)
        {
            FrameworkElement control = sender as FrameworkElement;
            if (control == null)
                return;
    
            SelectableItem item = control.DataContext as SelectableItem;
            if (item == null)
                return;
    
            string yourValue = item.SubjectId;
        }
    

    I strongly recommend you read about MVVM and bindings.

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

Sidebar

Related Questions

Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello everybody I have this string: [JOLLY BLU at STAY SHIP, Voy: 0275/11] How
Hello everybody I have a question: I have a array String[] parte and I
Hello everybody! I have a SQL (see above) and i would like to know
Note: Using Monotouch and doing all the UI Programatically. Hello everybody, I have a
Suppose I have String str=Hello $everybody$. How $are$ you $all$; From above string, I
My string contain a lot of HTML entities, like this &#x22;Hello&nbsp;&lt;everybody&gt;&nbsp;there&#x22; And I want
Everybody, Hello! I have a simple stub client for the cxf web-service (spring app).
Hello Everybody i asked this question few hours ago C# get username from string.
Hello everybody :) I have misunderstanging in setPropety in using Bean ? when I

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.