Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
WPF空选项卡控件内容_Wpf_Tabcontrol - Fatal编程技术网

WPF空选项卡控件内容

WPF空选项卡控件内容,wpf,tabcontrol,Wpf,Tabcontrol,我使用一个TabControl来托管工作空间,方法如johnsmith的文章所述。我想知道是否有一种方法可以在没有选项卡的情况下向选项卡控件添加内容,如图像。有点像默认的或空的行为。我想有应用程序的标志,或者一些有用的箭头a-la铬的第一次使用标签 编辑:这可能有点复杂。我在下面显示的标准选项卡控件上尝试了Chad的解决方案。但是,我用于工作区的tabcontrol是由使用datatemplate的内容控件呈现的,我无法让他的解决方案使用它。HB的解决方案做了一些改变 <DataTempl

我使用一个TabControl来托管工作空间,方法如johnsmith的文章所述。我想知道是否有一种方法可以在没有选项卡的情况下向选项卡控件添加内容,如图像。有点像默认的或空的行为。我想有应用程序的标志,或者一些有用的箭头a-la铬的第一次使用标签

编辑:这可能有点复杂。我在下面显示的标准选项卡控件上尝试了Chad的解决方案。但是,我用于工作区的tabcontrol是由使用datatemplate的内容控件呈现的,我无法让他的解决方案使用它。HB的解决方案做了一些改变

<DataTemplate x:Key="WorkspacesTemplate">
    <Grid>
        <Image Name="image1" Stretch="Uniform" Source="/Affinity;component/Images/affinity_logo.png" Margin="20"/>
        <TabControl IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" 
                ItemTemplate="{StaticResource ClosableTabItemTemplate}" Margin="4">
            <TabControl.Style>
                <Style TargetType="TabControl">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}"
                        Value="0">
                            <Setter Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TabControl.Style>
        <TabControl.Template>
            <ControlTemplate TargetType="TabControl">
                <Grid Background="White">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <ScrollViewer HorizontalScrollBarVisibility="Auto"  VerticalScrollBarVisibility="Hidden" >
                        <StackPanel x:Name="HeaderPanel"
                            Orientation="Horizontal"
                            Panel.ZIndex ="1" 
                            KeyboardNavigation.TabIndex="1"
                            Grid.Column="0"
                            Grid.Row="0"
                            Margin="2,2,2,0"
                            IsItemsHost="true"/>
                    </ScrollViewer>
                        <ContentPresenter x:Name="PART_SelectedContentHost" Grid.Row="1" 
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                          Margin="{TemplateBinding Padding}"
                                          ContentSource="SelectedContent"/>
                </Grid>
            </ControlTemplate>
        </TabControl.Template>
    </TabControl>
    </Grid>
</DataTemplate>

如果图像中没有任何项目,您可以将TabControl覆盖在图像上并将其隐藏,例如:

<Grid>
    <Image />
    <TabControl>
        <TabControl.Style>
            <Style TargetType="TabControl">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}"
                            Value="0">
                        <Setter Property="Visibility" Value="Hidden" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TabControl.Style>
    </TabControl>
</Grid>

或者您也可以交换ContentControl的内容,也可以使用触发器,正如在上面的方法中,两个控件都会影响布局。e、 g

<ContentControl>
    <ContentControl.Resources>
        <Image x:Key="Image"/>
        <TabControl x:Key="TabControl" ItemsSource="{Binding Data}" />
    </ContentControl.Resources>
    <ContentControl.Style>
        <Style TargetType="ContentControl">
            <Setter Property="Content" Value="{StaticResource TabControl}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Data.Count}"
                        Value="0">
                    <Setter Property="Content" Value="{StaticResource Image}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ContentControl.Style>
</ContentControl>


注意这里的
DataTrigger
应该直接绑定到
TabControl
中使用的相同集合。这是因为如果您绑定到
TabControl.Items.Count
,则当卸载
TabControl
时,此绑定将在触发器触发时中断。

您可以向选项卡控件添加背景。XAML看起来像这样:

<TabControl Height="290" HorizontalAlignment="Left" Margin="12,350,0,0" Name="TabControl" VerticalAlignment="Top" Width="481" TabIndex="200">
    <TabControl.Background>
        <ImageBrush ImageSource="/EffectsViewer;component/res/someimage.png" />
    </TabControl.Background>
</TabControl>


只需确保您使用的图像在您的资源中。在VisualStudio中使用GUI添加并不困难。至于添加控件,这可能有点复杂。我认为要做到这一点,您需要在控件为空时将其隐藏在后面,或者从中派生并自己实现它。

这看起来很有希望,我在问题中添加了一些代码,以显示我的内容控件是如何绑定到工作区集合的。我现在正努力让他们两个都工作。