如何使用多个选项卡控件,以及如何使用按钮调用选定的选项卡控件

发布于 2024-09-02 01:44:03 字数 4023 浏览 2 评论 0原文

我试图为左侧的每个按钮分配自己的选项卡控件。也就是说,例如,当按下“接收表单”按钮时,它将有自己的一组选项卡(它自己的选项卡控件),

我是否应该在画板上放置多个选项卡控件,或者是否有一种方法可以以编程方式更改选项卡的名称当按下左侧的按钮时,选项卡和内容?

这是到目前为止的代码:

<Window
 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"
 x:Class="service.MainWindow"
 x:Name="Window"
 Title="MainWindow"
 Width="687" Height="480" mc:Ignorable="d">
 <Window.Resources>
  <Storyboard x:Key="OnLoaded1"/>
 </Window.Resources>
 <Window.Triggers>
  <EventTrigger RoutedEvent="FrameworkElement.Loaded">
   <BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/>
  </EventTrigger>
 </Window.Triggers>

 <Grid x:Name="LayoutRoot" Margin="0,0,-16,1">
  <Grid.ColumnDefinitions>
   <ColumnDefinition Width="0*"/>
   <ColumnDefinition/>
  </Grid.ColumnDefinitions>
  <DockPanel Margin="8,8,0,7" LastChildFill="False" Grid.Column="1" HorizontalAlignment="Left" Width="660">
   <Menu VerticalAlignment="Top" Width="657" Height="32">
    <MenuItem x:Name="file" Header="File"/>
    <MenuItem x:Name="edit" Header="Edit">
     <MenuItem Width="100" Height="100" Header="MenuItem"/>
    </MenuItem>
    <MenuItem x:Name="view" Header="View"/>
    <MenuItem x:Name="preferences" Header="Preferences"/>
    <MenuItem x:Name="help" Header="Help"/>
   </Menu>
  </DockPanel>
  <TabControl x:Name="tabwin" Margin="137.224,46,19,7" Grid.Column="1">
   <TabItem x:Name="intakeformsub" Header="Elegibility Form">
    <Grid HorizontalAlignment="Left" Width="490"/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid>
     <Grid.ColumnDefinitions>
      <ColumnDefinition Width="0.567*"/>
      <ColumnDefinition Width="0.433*"/>
     </Grid.ColumnDefinitions>
    </Grid>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid>
     <Grid.ColumnDefinitions>
      <ColumnDefinition Width="0.735*"/>
      <ColumnDefinition Width="0.265*"/>
     </Grid.ColumnDefinitions>
    </Grid>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
  </TabControl>
  <Grid x:Name="___buttontab" Margin="11.205,61,0,0" Grid.Column="1" HorizontalAlignment="Left" Width="122.019" VerticalAlignment="Top" Height="276">
   <Button VerticalAlignment="Top" Height="36" Content="Button"/>
   <Button Margin="0,40,0,0" Content="Oasis Assessments" VerticalAlignment="Top" Height="36"/>
   <Button Margin="0,80,0,0" VerticalAlignment="Top" Height="36" Content="Plan of Care"/>
   <Button Margin="0,120,0,0" VerticalAlignment="Top" Height="36" Content="Medication Profile" RenderTransformOrigin="0.421,5.556"/>
   <Button Margin="0,0,0,80" VerticalAlignment="Bottom" Height="36" Content="Clinical Notes"/>
   <Button Margin="0,0,0,40" VerticalAlignment="Bottom" Height="36" Content="Infection Control"/>
   <Button x:Name="intakeformbtn" VerticalAlignment="Top" Height="36" Content="Intake Form" Click="intakeform">
    <Button.BindingGroup>
     <BindingGroup/>
    </Button.BindingGroup>
   </Button>
   <Button VerticalAlignment="Bottom" Height="36" Content="Discharge Summary"/>
  </Grid>
  <ProgressBar HorizontalAlignment="Left" Margin="8,0,0,7" VerticalAlignment="Bottom" Width="104.795" Height="19" Grid.Column="1"/>
 </Grid>
</Window>

I am trying to assign each button on the left its own Tab control. That is for example, when the Intake form button is pushed, it will have its own set of tabs (its own tabcontrols)

am I supposed to place multiple tab controls on the artboard, or is there a way to programmatically change the names of the tabs, and there contents, when a button is pushed on the left?

here is the code so far:

<Window
 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"
 x:Class="service.MainWindow"
 x:Name="Window"
 Title="MainWindow"
 Width="687" Height="480" mc:Ignorable="d">
 <Window.Resources>
  <Storyboard x:Key="OnLoaded1"/>
 </Window.Resources>
 <Window.Triggers>
  <EventTrigger RoutedEvent="FrameworkElement.Loaded">
   <BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/>
  </EventTrigger>
 </Window.Triggers>

 <Grid x:Name="LayoutRoot" Margin="0,0,-16,1">
  <Grid.ColumnDefinitions>
   <ColumnDefinition Width="0*"/>
   <ColumnDefinition/>
  </Grid.ColumnDefinitions>
  <DockPanel Margin="8,8,0,7" LastChildFill="False" Grid.Column="1" HorizontalAlignment="Left" Width="660">
   <Menu VerticalAlignment="Top" Width="657" Height="32">
    <MenuItem x:Name="file" Header="File"/>
    <MenuItem x:Name="edit" Header="Edit">
     <MenuItem Width="100" Height="100" Header="MenuItem"/>
    </MenuItem>
    <MenuItem x:Name="view" Header="View"/>
    <MenuItem x:Name="preferences" Header="Preferences"/>
    <MenuItem x:Name="help" Header="Help"/>
   </Menu>
  </DockPanel>
  <TabControl x:Name="tabwin" Margin="137.224,46,19,7" Grid.Column="1">
   <TabItem x:Name="intakeformsub" Header="Elegibility Form">
    <Grid HorizontalAlignment="Left" Width="490"/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid>
     <Grid.ColumnDefinitions>
      <ColumnDefinition Width="0.567*"/>
      <ColumnDefinition Width="0.433*"/>
     </Grid.ColumnDefinitions>
    </Grid>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid>
     <Grid.ColumnDefinitions>
      <ColumnDefinition Width="0.735*"/>
      <ColumnDefinition Width="0.265*"/>
     </Grid.ColumnDefinitions>
    </Grid>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
   <TabItem Header="TabItem">
    <Grid/>
   </TabItem>
  </TabControl>
  <Grid x:Name="___buttontab" Margin="11.205,61,0,0" Grid.Column="1" HorizontalAlignment="Left" Width="122.019" VerticalAlignment="Top" Height="276">
   <Button VerticalAlignment="Top" Height="36" Content="Button"/>
   <Button Margin="0,40,0,0" Content="Oasis Assessments" VerticalAlignment="Top" Height="36"/>
   <Button Margin="0,80,0,0" VerticalAlignment="Top" Height="36" Content="Plan of Care"/>
   <Button Margin="0,120,0,0" VerticalAlignment="Top" Height="36" Content="Medication Profile" RenderTransformOrigin="0.421,5.556"/>
   <Button Margin="0,0,0,80" VerticalAlignment="Bottom" Height="36" Content="Clinical Notes"/>
   <Button Margin="0,0,0,40" VerticalAlignment="Bottom" Height="36" Content="Infection Control"/>
   <Button x:Name="intakeformbtn" VerticalAlignment="Top" Height="36" Content="Intake Form" Click="intakeform">
    <Button.BindingGroup>
     <BindingGroup/>
    </Button.BindingGroup>
   </Button>
   <Button VerticalAlignment="Bottom" Height="36" Content="Discharge Summary"/>
  </Grid>
  <ProgressBar HorizontalAlignment="Left" Margin="8,0,0,7" VerticalAlignment="Bottom" Width="104.795" Height="19" Grid.Column="1"/>
 </Grid>
</Window>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清泪尽 2024-09-09 01:44:08

解决此问题的一种方法是使用另一个 TabControl 而不是按钮,但选项卡标题在视觉上被重新设计为按钮而不是选项卡。这样您甚至不必处理按钮更改。

尝试以下代码:

<Window
 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"
 x:Class="WpfApplication16.MainWindow"
 x:Name="Window"
 Title="MainWindow"
 Width="687" Height="480" mc:Ignorable="d">
    <Window.Resources>
        <Storyboard x:Key="OnLoaded1"/>

        <Style TargetType="{x:Type TabItem}" x:Key="TabButtonStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <ToggleButton IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=IsSelected, Mode=TwoWay}"
                                                    Margin="10">
                            <ContentPresenter ContentSource="Header" />
                        </ToggleButton>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/>
        </EventTrigger>
    </Window.Triggers>

    <Grid x:Name="LayoutRoot" Margin="0,0,-16,1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0*"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <DockPanel Margin="8,8,0,7" LastChildFill="False" Grid.Column="1" HorizontalAlignment="Left" Width="660">
            <Menu VerticalAlignment="Top" Width="657" Height="32">
                <MenuItem x:Name="file" Header="File"/>
                <MenuItem x:Name="edit" Header="Edit">
                    <MenuItem Width="100" Height="100" Header="MenuItem"/>
                </MenuItem>
                <MenuItem x:Name="view" Header="View"/>
                <MenuItem x:Name="preferences" Header="Preferences"/>
                <MenuItem x:Name="help" Header="Help"/>
            </Menu>
        </DockPanel>
        <TabControl Margin="0,61,0,0" Grid.Column="1" ItemContainerStyle="{StaticResource TabButtonStyle}" TabStripPlacement="Left">
            <TabControl.Items>
                <TabItem Header="Button">
                    <Grid>
                        <TabControl x:Name="tabwin">
                            <TabItem x:Name="intakeformsub" Header="Elegibility Form">
                                <Grid HorizontalAlignment="Left" Width="490"/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.567*"/>
                                        <ColumnDefinition Width="0.433*"/>
                                    </Grid.ColumnDefinitions>
                                </Grid>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.735*"/>
                                        <ColumnDefinition Width="0.265*"/>
                                    </Grid.ColumnDefinitions>
                                </Grid>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                        </TabControl>
                        <ProgressBar HorizontalAlignment="Left" Margin="8,0,0,7" VerticalAlignment="Bottom" Width="104.795" Height="19" Grid.Column="1"/>
                    </Grid>
                </TabItem>
                <TabItem Header="Oasis Assessments">
                    Foo
                </TabItem>
                <TabItem Header="Plan of Care">
                    Bar
                </TabItem>
                <TabItem Header="Medication Profile">
                </TabItem>
                <TabItem Header="Clinical Notes">
                </TabItem>
                <TabItem Header="Infection Control">
                </TabItem>
                <TabItem Header="Intake Form">
                </TabItem>
            </TabControl.Items>
        </TabControl>
    </Grid>
</Window>

A way to solve this problem is to use another TabControl instead of buttons, but where the tab headers are retemplated to be buttons insteads of tabs visually. This way you don't even have to handle the button changes.

Try the following code:

<Window
 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"
 x:Class="WpfApplication16.MainWindow"
 x:Name="Window"
 Title="MainWindow"
 Width="687" Height="480" mc:Ignorable="d">
    <Window.Resources>
        <Storyboard x:Key="OnLoaded1"/>

        <Style TargetType="{x:Type TabItem}" x:Key="TabButtonStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <ToggleButton IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=IsSelected, Mode=TwoWay}"
                                                    Margin="10">
                            <ContentPresenter ContentSource="Header" />
                        </ToggleButton>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/>
        </EventTrigger>
    </Window.Triggers>

    <Grid x:Name="LayoutRoot" Margin="0,0,-16,1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0*"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <DockPanel Margin="8,8,0,7" LastChildFill="False" Grid.Column="1" HorizontalAlignment="Left" Width="660">
            <Menu VerticalAlignment="Top" Width="657" Height="32">
                <MenuItem x:Name="file" Header="File"/>
                <MenuItem x:Name="edit" Header="Edit">
                    <MenuItem Width="100" Height="100" Header="MenuItem"/>
                </MenuItem>
                <MenuItem x:Name="view" Header="View"/>
                <MenuItem x:Name="preferences" Header="Preferences"/>
                <MenuItem x:Name="help" Header="Help"/>
            </Menu>
        </DockPanel>
        <TabControl Margin="0,61,0,0" Grid.Column="1" ItemContainerStyle="{StaticResource TabButtonStyle}" TabStripPlacement="Left">
            <TabControl.Items>
                <TabItem Header="Button">
                    <Grid>
                        <TabControl x:Name="tabwin">
                            <TabItem x:Name="intakeformsub" Header="Elegibility Form">
                                <Grid HorizontalAlignment="Left" Width="490"/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.567*"/>
                                        <ColumnDefinition Width="0.433*"/>
                                    </Grid.ColumnDefinitions>
                                </Grid>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.735*"/>
                                        <ColumnDefinition Width="0.265*"/>
                                    </Grid.ColumnDefinitions>
                                </Grid>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                            <TabItem Header="TabItem">
                                <Grid/>
                            </TabItem>
                        </TabControl>
                        <ProgressBar HorizontalAlignment="Left" Margin="8,0,0,7" VerticalAlignment="Bottom" Width="104.795" Height="19" Grid.Column="1"/>
                    </Grid>
                </TabItem>
                <TabItem Header="Oasis Assessments">
                    Foo
                </TabItem>
                <TabItem Header="Plan of Care">
                    Bar
                </TabItem>
                <TabItem Header="Medication Profile">
                </TabItem>
                <TabItem Header="Clinical Notes">
                </TabItem>
                <TabItem Header="Infection Control">
                </TabItem>
                <TabItem Header="Intake Form">
                </TabItem>
            </TabControl.Items>
        </TabControl>
    </Grid>
</Window>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文