如何从tabitemex infragistics继承样式

时间:2014-09-29 05:12:00

标签: c# wpf infragistics

我正在使用infragistics tabcontrol控件。我的itemcontainer值基于对象属性。要清楚我的意思,请查看以下代码段。

WPF

<Window x:Class="DynamicTabControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:igWindows="http://infragistics.com/Windows"
        xmlns:igDp="http://infragistics.com/DataPresenter"
        xmlns:igThemes="http://infragistics.com/Themes"
        Title="MainWindow" Height="450" Width="700">
    <Grid>
        <igWindows:XamTabControl Name="xamTabCtrl" ItemsSource="{Binding Collection}" Theme="Metro">
                <igWindows:XamTabControl.ItemContainerStyle>
                    <Style TargetType="{x:Type igWindows:TabItemEx}" BasedOn="{x:Static igThemes:DataPresenterMetro.LabelPresenter}">
                        <Setter Property="Header" Value="{Binding Path=Header}"/>
                    </Style>
                </igWindows:XamTabControl.ItemContainerStyle>
                <igWindows:XamTabControl.ContentTemplate>
                <DataTemplate>
                    <igDp:XamDataGrid Theme="Metro"
                  DataSource="{Binding Logins}" IsGroupByAreaExpanded="False" GroupByAreaLocation="None" GroupByAreaMode="DefaultFieldLayoutOnly"/>
                </DataTemplate>
            </igWindows:XamTabControl.ContentTemplate>
        </igWindows:XamTabControl>
    </Grid>
</Window>

和部分类

   public partial class MainWindow : Window
    {
        private ObservableCollection<Model> collection;

        public ObservableCollection<Model> Collection
        {
            get { return collection; }
        }

        public MainWindow()
        {
            InitializeComponent();
            collection = new ObservableCollection<Model>()
            {
                new Model() { Header = "Tab1"},
                new Model() { Header = "Tab2"},
                new Model() { Header = "Tab3"},
                new Model() { Header = "Tab4"},
            };
            DataContext = this;
            //xamTabCtrl.ItemsSource = collection;
        }
    }

和模型

public class Model
{
    private ObservableCollection<Login> _logins = new ObservableCollection<Login>()
    {
        new Login() { User = "User", Password = "Password"},
        new Login() { User = "User", Password = "Password"},
        new Login() { User = "User", Password = "Password"},
    };

    public string Header { get; set; }

    public ObservableCollection<Login> Logins
    {
        get { return _logins; }
    }
}

当我编译应用程序时,我得到了错误

{"Can only base on a Style with target type that is base type 'TabItemEx'."}

我可以从infragistics主题继承这种风格吗?

1 个答案:

答案 0 :(得分:0)

我找到了。我发现了继承类。

  <Style TargetType="{x:Type igWindows:TabItemEx}" BasedOn="{x:Static igThemes:PrimitivesMetro.TabItemEx}">
                <Setter Property="Header" Value="{Binding Path=Header}"/>
            </Style>