This is a migrated thread and some comments may be shown as answers.

binding issue

2 Answers 81 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Volkmar
Top achievements
Rank 1
Volkmar asked on 10 Nov 2010, 05:25 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Kiril Stanoev
Telerik team
answered on 11 Nov 2010, 03:14 PM
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
0
Volkmar
Top achievements
Rank 1
answered on 11 Nov 2010, 04:12 PM
That works great! Thanks a lot!
Tags
TabControl
Asked by
Volkmar
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Volkmar
Top achievements
Rank 1
Share this question
or