Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Silverlight中构建动态TabControl_Silverlight_Xaml_Dynamic_Silverlight 4.0_Tabcontrol - Fatal编程技术网

在Silverlight中构建动态TabControl

在Silverlight中构建动态TabControl,silverlight,xaml,dynamic,silverlight-4.0,tabcontrol,Silverlight,Xaml,Dynamic,Silverlight 4.0,Tabcontrol,我想在Silverlight中构建一个TabControl,它由一组对象驱动。我将在下面展示一个我正在尝试原型化的非常基本的设置的代码 MainPage.xaml <UserControl x:Class="DataDrivenTabControl.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/20

我想在Silverlight中构建一个TabControl,它由一组对象驱动。我将在下面展示一个我正在尝试原型化的非常基本的设置的代码

MainPage.xaml

<UserControl x:Class="DataDrivenTabControl.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:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:local="clr-namespace:DataDrivenTabControl"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<UserControl.DataContext>
    <local:MainPage_ViewModel/>
</UserControl.DataContext>

<StackPanel>
    <controls:TabControl>
        <!-- What do I need to do here for a Template? -->
    </controls:TabControl>
</StackPanel>
在本例中,我真正想做的就是让TabControl显示一个选项卡的动态列表,该列表将绑定到当前实现标题中的集合选项卡1和选项卡2。单击选项卡时,可能会有一个简单的按钮,其中按钮的内容将绑定到选项卡Item_DataViewModel上的ButtonDescription。这是非常基本的,但如果我能让它工作,我肯定能够实现我的解决方案的其余部分

我确信这必须通过TabControl上的模板来完成,但我只是让它空着,希望有人能给我指出正确的方向


任何帮助都将不胜感激,谢谢

通过使用Telerik的RadTabControl,我能够让它按预期工作,如下所示。我使用Telerik的版本,因为ItemSource是IEnumerable,而不是TabItems的集合

<telerikNavigation:RadTabControl ItemsSource="{Binding CollectionOfTabs}">
        <telerikNavigation:RadTabControl.ItemContainerStyle>
            <Style TargetType="telerikNavigation:RadTabItem">
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding TabDescription}"/>
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Button Content="{Binding ButtonDescription}" Width="100" HorizontalAlignment="Center"/>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </telerikNavigation:RadTabControl.ItemContainerStyle>
    </telerikNavigation:RadTabControl>
public class TabItem_DataViewModel : Base_ViewModel
{
    public string TabDescription
    {
        get { return tabDescription; }
        set
        {
            if (tabDescription != value)
            {
                tabDescription = value;
                OnPropertyChanged("TabDescription");
            }
        }
    }
    private string tabDescription = string.Empty;

    public string ButtonDescription
    {
        get { return buttonDescription; }
        set
        {
            if (buttonDescription != value)
            {
                buttonDescription = value;
                OnPropertyChanged("ButtonDescription");
            }
        }
    }
    private string buttonDescription = string.Empty;
}
<telerikNavigation:RadTabControl ItemsSource="{Binding CollectionOfTabs}">
        <telerikNavigation:RadTabControl.ItemContainerStyle>
            <Style TargetType="telerikNavigation:RadTabItem">
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding TabDescription}"/>
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Button Content="{Binding ButtonDescription}" Width="100" HorizontalAlignment="Center"/>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </telerikNavigation:RadTabControl.ItemContainerStyle>
    </telerikNavigation:RadTabControl>