I'm evaluating Telerik controls for a LOB application, and I found something that I can't userstand. What I'm trying to achieve is displaying a list of UserControl inside a TabControl and bind some properties in the HeaderTemplate of the TabItem.
If I bind directly yo a list of UserControls this isn't working.
MainPage.xaml
MAinPage.xaml.cs
PageOne.xaml
PageOne.xaml.cs
PageTwo is the same as page one just change number :)
I'm not an expert in Silverlight developing so maybe I'm missing something obvious.
Thanks
Luca Lusetti
If I bind directly yo a list of UserControls this isn't working.
MainPage.xaml
<UserControl x:Class="SilverlightApplication1.MainPage" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> |
<UserControl.Resources> |
<DataTemplate x:Key="TabHeaderTeamplate"> |
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> |
<TextBlock Text="{Binding DisplayName}" /> |
</StackPanel> |
</DataTemplate> |
</UserControl.Resources> |
<StackPanel> |
<TextBlock Text="TabControl bound to List[UserControl], header template not working" /> |
<nav:RadTabControl x:Name="boundTabControl"> |
<nav:RadTabControl.ItemContainerStyle> |
<Style TargetType="nav:RadTabItem"> |
<Setter Property="HeaderTemplate" Value="{StaticResource TabHeaderTeamplate}" /> |
</Style> |
</nav:RadTabControl.ItemContainerStyle> |
</nav:RadTabControl> |
<TextBlock Text="TabControl bound to List[UserControlWrapper], header template working" /> |
<nav:RadTabControl x:Name="boundTabControl2"> |
<nav:RadTabControl.ItemTemplate> |
<DataTemplate> |
<ContentPresenter Content="{Binding Content}" /> |
</DataTemplate> |
</nav:RadTabControl.ItemTemplate> |
<nav:RadTabControl.ItemContainerStyle> |
<Style TargetType="nav:RadTabItem"> |
<Setter Property="HeaderTemplate" Value="{StaticResource TabHeaderTeamplate}" /> |
</Style> |
</nav:RadTabControl.ItemContainerStyle> |
</nav:RadTabControl> |
</StackPanel> |
</UserControl> |
MAinPage.xaml.cs
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
namespace SilverlightApplication1 |
{ |
public partial class MainPage : UserControl |
{ |
public MainPage() |
{ |
InitializeComponent(); |
boundTabControl.ItemsSource = new List<UserControl>() |
{ |
new PageOne(), |
new PageTwo(), |
}; |
boundTabControl2.ItemsSource = new List<UserControlWrapper>() |
{ |
new UserControlWrapper{Content = new PageOne(), DisplayName = "PageONE"}, |
new UserControlWrapper{Content = new PageTwo(), DisplayName = "PageTWO"}, |
}; |
} |
} |
public class UserControlWrapper |
{ |
public string DisplayName { get; set; } |
public UserControl Content { get; set; } |
} |
} |
PageOne.xaml
<UserControl x:Class="SilverlightApplication1.PageOne" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
Width="400" Height="300"> |
<Grid x:Name="LayoutRoot" Background="White"> |
<TextBlock Text="Page ONE" /> |
</Grid> |
</UserControl> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
namespace SilverlightApplication1 |
{ |
public partial class PageOne : UserControl |
{ |
public string DisplayName { get { return "PageONE"; } } |
public PageOne() |
{ |
InitializeComponent(); |
} |
} |
} |
PageTwo is the same as page one just change number :)
I'm not an expert in Silverlight developing so maybe I'm missing something obvious.
Thanks
Luca Lusetti