I'm relatively new to WPF and currently evaluating Telerik components. I got stuck when trying to bind RadTabControl items to content control objects. Probably the automatically generated RadTabItem doesn't like to wrap a content control (e.g. HeaderedContentControl) because regular objects work as expected. Am I trying to accomplish something that can't be done? Below you'll find a example that illustrates what I mean. Any help will be appreciated very much.
XAML:
Code behind:
View model:
XAML:
<
Window
x:Class
=
"RadControlsWpfApp1.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local
=
"clr-namespace:RadControlsWpfApp1"
xmlns:diagnostics
=
"clr-namespace:System.Diagnostics;assembly=WindowsBase"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Window.Resources
>
<
DataTemplate
x:Key
=
"TabItemTemplate"
>
<
StackPanel
Orientation
=
"Horizontal"
VerticalAlignment
=
"Center"
>
<
Image
Width
=
"18"
Height
=
"18"
Source
=
"{Binding Icon}"
Stretch
=
"Fill"
Margin
=
"0,0,3,0"
/>
<
TextBlock
Text
=
"{Binding Header, diagnostics:PresentationTraceSources.TraceLevel=High}"
/>
</
StackPanel
>
</
DataTemplate
>
</
Window.Resources
>
<
Grid
>
<
telerik:RadTabControl
ItemsSource
=
"{Binding Tabs}"
ItemTemplate
=
"{StaticResource TabItemTemplate}"
/>
</
Grid
>
</
Window
>
Code behind:
using System.Windows;
namespace RadControlsWpfApp1
{
/// <
summary
>
/// Interaction logic for MainWindow.xaml
/// </
summary
>
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = new MainWindowViewModel();
InitializeComponent();
}
}
}
View model:
using System;
using System.Collections.ObjectModel;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Telerik.Windows.Controls.QuickStart;
namespace RadControlsWpfApp1
{
public class MainWindowViewModel
{
private BitmapImage Bullet = new BitmapImage(new Uri("/RadControlsWpfApp1;component/bullet_red.png", UriKind.Relative));
public ObservableCollection<
IItem
> Tabs { get; set; }
public MainWindowViewModel()
{
Tabs = new ObservableCollection<
IItem
>();
Tabs.Add(new ItemControl { Header = "Item 1", Icon = Bullet });
Tabs.Add(new Item { Header = "Item 2", Icon = Bullet });
}
}
public interface IItem
{
object Header { get; set; }
ImageSource Icon { get; set; }
}
public class Item : IItem
{
public object Header { get; set; }
public ImageSource Icon { get; set; }
}
public class ItemControl : HeaderedContentControl, IItem
{
public ImageSource Icon { get; set; }
}
}