WPF对此要求的控制或方法是什么?

Gre*_*reg 2 .net c# wpf tabcontrol

刚刚对WPF不熟悉我不确定对于WPF应用程序来说,哪种控制或方法最适合此要求.

  • 我想提供一个信息摘要表,但用户应该能够决定根据以下任一方式查看信息:"所有时间",月,周或日.
  • 我希望在视觉上可以选择选项出现在本节的顶部,并将其显示为TabControl
  • 然而,我不确定TabControl是否是为每个Tab项重复表的最佳选择
  • 所以功能上的整体功能只是顶部的单选按钮,但我想要的是TabControl外观

实现TabControl外观的最佳方法是什么,但是使用编程方法,我不必在每个Tab项中重复这些内容?

例如,我是否会使用TabControl然后使用WPF模板在每个Tab项中执行相当于包含但具有不同输入参数的包含?(之前没有使用过WPF模板)

谢谢

小智 7

既然你想要一组RadioButtons 的行为而你想要a的视觉外观TabItem,你应该使用RadioButton控件并设置它们的样式,使它们看起来像TabItem控件.这是一个非常简单的例子:

替代文字

<Window x:Class="TabTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <Style TargetType="{x:Type RadioButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Border x:Name="tabBorder" BorderThickness="1" BorderBrush="Black"
                                Margin="0,0,-4,0"
                                CornerRadius="2,12,0,0"
                                Background="White"
                                SnapsToDevicePixels="True">
                            <ContentPresenter                                 
                                Margin="12,2,12,2"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Left"
                                RecognizesAccessKey="True"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Panel.ZIndex" Value="100" />
                                <Setter TargetName="tabBorder" Property="Background" Value="LightBlue" />
                                <Setter TargetName="tabBorder" Property="BorderThickness" Value="1,1,1,0" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid Margin="4">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,-1" Panel.ZIndex="1">
            <RadioButton>All Time</RadioButton>
            <RadioButton IsChecked="True">Month</RadioButton>
            <RadioButton>Week</RadioButton>
            <RadioButton>Day</RadioButton>
        </StackPanel>
        <Border Grid.Row="1" Background="LightBlue" 
                BorderThickness="1" BorderBrush="Black"
                SnapsToDevicePixels="True">
            <Button Margin="10" Grid.Row="1">This is a test</Button>
        </Border>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

在此示例中,Button您将放置摘要表的位置.