CheckBox IsChecked Binding within a GroupHeaderTemplate doesn't work

4 posts, 0 answers
  1. Ville
    Ville avatar
    18 posts
    Member since:
    Apr 2010

    Posted 23 Nov 2010 Link to this post

    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?
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 24 Nov 2010 Link to this post

    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
  3. DevCraft banner
  4. Ville
    Ville avatar
    18 posts
    Member since:
    Apr 2010

    Posted 24 Nov 2010 Link to this post

    So, you're saying it is not possible to totally customize the values of the groupheadertemplate?
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 25 Nov 2010 Link to this post

    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
Back to Top