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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:33:30+00:00 2026-05-11T19:33:30+00:00

Near total WPF noob. So I hooked up a combobox to have checkboxes using

  • 0

Near total WPF noob. So I hooked up a combobox to have checkboxes using the following item template:

<ComboBox.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <CheckBox Checked="{Binding IsSelected}"
                   Width="20" Name="chkDayName" Click="chkDayName_Click"/>
            <TextBlock Text="{Binding DayOfWeek}"
                   Width="100"  Name="txtDayName" />
        </StackPanel>
    </DataTemplate>
</ComboBox.ItemTemplate>

On the actual event of a person clicking a checkbox, i catch the event in chkDayName_Click method. I have the following questions:

How do I find out values of the corresponding TextBlock in the item template?
How do i find out the index of the item that was clicked?
Is there a way to get to the parent?

Thanks.

  • 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-11T19:33:31+00:00Added an answer on May 11, 2026 at 7:33 pm

    If I understand it you want to know which combobox items are checked? You can use the chkDayName_Click for that and add the name of the day as Tag of the CheckBox. This feels very Winforms. In WPF you normally let your databinding handle functionality like this. Below is some code that will display selected item in a textbox and a list of checked weekdays.

    XAML:

    <Window x:Class="DayComboBoxDemo.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    
        <Window.Resources>
    
            <CollectionViewSource x:Key="checkedWeekdays" Source="{Binding Path=WeekDays}" Filter="IsCheckedFilter" />
    
        </Window.Resources>
    
        <StackPanel>
            <ComboBox
                ItemsSource="{Binding Path=WeekDays}"
                SelectedItem="{Binding Path=SelectedWeekDay}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox 
                                IsChecked="{Binding Path=IsChecked}"
                                Width="20" Click="chkDayName_Click"/>
                            <TextBlock 
                                Text="{Binding DayOfWeek}" Width="100" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <TextBlock Text="{Binding Path=SelectedWeekDay.DayOfWeek}" />
            <ListBox
                DisplayMemberPath="DayOfWeek"
                ItemsSource="{Binding Source={StaticResource checkedWeekdays}}" />
        </StackPanel>
    </Window>
    

    Code behind:

    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Data;
    
    namespace DayComboBoxDemo
    {
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
    
                List<WeekDay> weekDays = new List<WeekDay>();
                foreach (DayOfWeek dayOfWeek in System.Enum.GetValues(typeof(DayOfWeek)))
                {
                    weekDays.Add(new WeekDay() { DayOfWeek = dayOfWeek });
                }
    
                WeekDays = weekDays;
    
                _checkedWeekdays = FindResource("checkedWeekdays") as CollectionViewSource;
    
                DataContext = this;
            }
    
            public IEnumerable<WeekDay> WeekDays { get; set; }
    
            public WeekDay SelectedWeekDay
            {
                get { return (WeekDay)GetValue(SelectedWeekDayProperty); }
                set { SetValue(SelectedWeekDayProperty, value); }
            }
    
            public static readonly DependencyProperty SelectedWeekDayProperty =
                DependencyProperty.Register("SelectedWeekDay", 
                                            typeof(WeekDay), 
                                            typeof(Window1), 
                                            new UIPropertyMetadata(null));
    
            private void chkDayName_Click(object sender, RoutedEventArgs e)
            {
                _checkedWeekdays.View.Refresh();
            }
    
            private void IsCheckedFilter(object sender, FilterEventArgs e)
            {
                WeekDay weekDay = e.Item as WeekDay;
                e.Accepted = weekDay.IsChecked;
            }
    
            private CollectionViewSource _checkedWeekdays;
        }
    
        public class WeekDay
        {
            public DayOfWeek DayOfWeek { get; set; }
            public bool IsChecked { get; set; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display some WPF elements near to the selected item of a
I have the following problem, in near future I will need to write a
I am getting Incorrect syntax near the keyword 'select' after executing the following code.
I have the following code in SQL (2005) which calculates the avarage user logins
I have implemented MGTwitterEngine in my application and it works near to perfect. The
I might have to address some development improvement projects in C# in the near
We are using a mysql database w/ about 150,000 records (names) total. Our searches
I am using SSRS 2008 and i have a stored proc which currently uses
I have near about 100 entities and each entity has custom property of byteArray
I am using the opengl es to display objects. when the object is near

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.