This is a migrated thread and some comments may be shown as answers.
CheckBox IsChecked Binding within a GroupHeaderTemplate doesn't work
3 Answers 77 Views
This is a migrated thread and some comments may be shown as answers.
Ville
Top achievements
Rank 1
Ville asked on 23 Nov 2010, 08:40 PM
Good morning,

I would like to know if there is a way I can pull a property value from an ObservableCollection<SectionData> which is inside my View Model class. I can't find a way to do it. Here is my XAML:

<telerikGridView:RadGridView.GroupHeaderTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <CheckBox IsChecked="{Binding IsChecked, Source={StaticResource FoodSafetyViewModel}, Mode=TwoWay}" Grid.Column="0"/>
                                <TextBlock Text="{Binding Section, Source={StaticResource FoodSafetyViewModel}, Mode=OneTime}" Grid.Column="1"/>
                            </Grid>
                        </DataTemplate>
                    </telerikGridView:RadGridView.GroupHeaderTemplate>

Where FoodSafetyViewModel is defined as follows:
<navigation:Page.Resources>
        <local:FoodSafetyViewModel x:Key="FoodSafetyViewModel"/>
    </navigation:Page.Resources>


HEre is my ViewModel class:
namespace RemoteEntry.Classes
{
    public class FoodSafetyViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private ObservableCollection<SectionData> sectionDatas;
        private ObservableCollection<ViolationData> violationDatas;
        private ObservableCollection<ViolationItemData> violationItemDatas;
        private ObservableCollection<AutoCommentData> autoCommentDatas;
        private object selectedItem;

        public ObservableCollection<SectionData> SectionDatas
        {
            get
            {
                if (this.sectionDatas == null)
                {
                    this.sectionDatas = SectionData.GetSectionData();
                }

                return this.sectionDatas;
            }
        }

        public ObservableCollection<ViolationData> ViolationDatas
        {
            get
            {
                if (this.violationDatas == null)
                {
                    this.violationDatas = ViolationData.GetViolationData();
                }

                return this.violationDatas;
            }
        }
...

and here is my SecionData class:
namespace RemoteEntry.Classes
{
    public class SectionData : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private string section;
        private bool isChecked;

        public string Section
        {
            get { return this.section; }
            set
            {
                if (value != this.section)
                {
                    this.section = value;
                    this.OnPropertyChanged("Section");
                }
            }
        }

        public bool IsChecked
        {
            get { return this.isChecked; }
            set
            {
                if (value != this.isChecked)
                {
                    this.isChecked = value;
                    this.OnPropertyChanged("(IsChecked");
                }
            }
        }

        public SectionData()
        {
        }

        public SectionData(string section, bool isChecked)
        {
            this.section = section;
            this.isChecked =  isChecked;
        }

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, args);
            }
        }

        private void OnPropertyChanged(string propertyName)
        {
            this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }

See snapshot attached.


Any suggestions?

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Nov 2010, 07:38 AM
Hello,

 The DataContext in this template is the group view model (Telerik.Windows.Controls.GridView.GroupViewModel) - not data items. 

Regards,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Ville
Top achievements
Rank 1
answered on 24 Nov 2010, 06:41 PM
So, you're saying it is not possible to totally customize the values of the groupheadertemplate?
0
Vlad
Telerik team
answered on 25 Nov 2010, 08:06 AM
Hi,

 I'm just trying to say that the DataContext is not your data item - you can use Group,Items to access data items for this group. 

Sincerely yours,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Asked by
Ville
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Ville
Top achievements
Rank 1
Share this question
or