binding issue

3 posts, 1 answers
  1. Volkmar
    Volkmar avatar
    6 posts
    Member since:
    Oct 2010

    Posted 10 Nov 2010 Link to this post

    I have a tabcontrol which I want to bind to a object list. The header of the tab as well as the content, a gridview, should be bound to the list of objects. However there are some problems with the binding. The header does not show and the content (grodview) only apears after selecting the tabs. Without selecting the ObjectName is shown on the first tab.

    C# Code:

    public class InfoWindowContent : INotifyPropertyChanged
    {
        public IDictionary<string, string> ContentList { get; set; }
        public string HeaderStr;
        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }
    public class ApDataContext : INotifyPropertyChanged
        {
            private ObservableCollection<InfoWindowContent> _infoContainer = new ObservableCollection<InfoWindowContent>();
            public event PropertyChangedEventHandler PropertyChanged;
            public User Login { get; private set; }
            public Farm Farm { get; private set; }
            public MapServiceMapServerAttributes Msa { get; set; }
      
      
      
            public ObservableCollection<InfoWindowContent> InfoContainer
            {
                get
                {
                    return _infoContainer;
                }
                set
                {
                    _infoContainer = value;
                    RaisePropertyChanged("InfoContainer");
                }
            }
    }

    <telerik:RadPaneGroup x:Name="RadPaneGroup_Info"  telerik:RadDocking.SerializationTag="RadPaneGroup_Info">
        <telerik:RadPane x:Name="InfoPane" Header="Information"
        <telerik:RadTabControl x:Name="tabControlInfo" ItemsSource="InfoContainer" Align="Left" SelectedIndex="0">
            <telerik:RadTabControl.ItemContainerStyle>
                <!--The style that will be applied to all the items-->
                <Style TargetType="telerik:RadTabItem">
                    <!--Setting the template for the headers.-->
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                    <TextBlock Text="{Binding HeaderStr}" 
                           FontSize="11" 
                           Margin="5 0 5 0" 
                           VerticalAlignment="Center" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" >
                                    <telerikGridView:RadGridView x:Name="RadGridViewInfo"                                                             
                                                 IsReadOnly="False"
                                                 ItemsSource="{Binding ContentList}"
                                                 AutoGenerateColumns="True"
                                                 ColumnWidth="Auto"
                                                 SelectionChanged="RadGridViewInfo_SelectionChanged"
                                                 ShowGroupPanel="False"
                                                 ShowColumnHeaders="False"
                                                 Background="White" VerticalGridLinesBrush="#46CBCBCB">
                                    </telerikGridView:RadGridView>
                                </Grid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </telerik:RadTabControl.ItemContainerStyle>
              
            </telerik:RadTabControl>
        </telerik:RadPane>
    </telerik:RadPaneGroup>


    Does anybody know whats going on? Thank you very much for any hint.

    Volkmar
  2. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 11 Nov 2010 Link to this post

    Hello Volkmar,

    I've made several changes to your project to make it work. Remember that you can do binding only to properties, not public variables. Therefore, you need to change the following things:

    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
     
            ApDataContext dataContext = new ApDataContext();
            InfoWindowContent window = new InfoWindowContent();
            window.HeaderStr = "Window #1";
            dataContext.InfoContainer.Add(window);
            this.DataContext = dataContext;
        }
     
        private void RadGridViewInfo_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
        {
     
        }
    }
     
    public class InfoWindowContent : INotifyPropertyChanged
    {
        public InfoWindowContent()
        {
            this.ContentList = Enumerable.Range(0, 20);
        }
     
        public IEnumerable ContentList { get; set; }
     
        public string HeaderStr
        {
            get;
            set;
        }
     
        public event PropertyChangedEventHandler PropertyChanged;
     
        public void RaisePropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }
     
     
    public class ApDataContext : INotifyPropertyChanged
    {
        private ObservableCollection<InfoWindowContent> _infoContainer = new ObservableCollection<InfoWindowContent>();
        public event PropertyChangedEventHandler PropertyChanged;
        public User Login { get; private set; }
        public Farm Farm { get; private set; }
        public MapServiceMapServerAttributes Msa { get; set; }
     
        public ObservableCollection<InfoWindowContent> InfoContainer
        {
            get
            {
                return _infoContainer;
            }
            set
            {
                _infoContainer = value;
                RaisePropertyChanged("InfoContainer");
            }
        }
     
        private void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
     
    }

    <telerik:RadPaneGroup x:Name="RadPaneGroup_Info"
            telerik:RadDocking.SerializationTag="RadPaneGroup_Info">
        <telerik:RadPane x:Name="InfoPane" Header="Information">
            <telerik:RadTabControl x:Name="tabControlInfo" ItemsSource="{Binding InfoContainer}"
                    Align="Left" SelectedIndex="0">
                <telerik:RadTabControl.ItemContainerStyle>
                    <!--The style that will be applied to all the items-->
                    <Style TargetType="telerik:RadTabItem">
                        <!--Setting the template for the headers.-->
                        <Setter Property="HeaderTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <TextBlock Text="{Binding HeaderStr}" FontSize="11"
                                            Margin="5 0 5 0" VerticalAlignment="Center" />
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <Grid HorizontalAlignment="Left" VerticalAlignment="Top"
                                            Margin="5">
                                        <telerik:RadGridView x:Name="RadGridViewInfo"
                                                IsReadOnly="False"
                                                ItemsSource="{Binding ContentList}"
                                                AutoGenerateColumns="True" ColumnWidth="Auto"
                                                SelectionChanged="RadGridViewInfo_SelectionChanged"
                                                ShowGroupPanel="False" ShowColumnHeaders="False"
                                                Background="White"
                                                VerticalGridLinesBrush="#46CBCBCB" />
                                    </Grid>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </telerik:RadTabControl.ItemContainerStyle>
            </telerik:RadTabControl>
        </telerik:RadPane>
    </telerik:RadPaneGroup>



    Give it a try and let me know if it helps.

    Regards,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Volkmar
    Volkmar avatar
    6 posts
    Member since:
    Oct 2010

    Posted 11 Nov 2010 Link to this post

    That works great! Thanks a lot!
Back to Top