2016-05-13 3 views
3

XAMLを使用してGUIをユーザーに提示するために、自分のアプリケーションに「タブ付き」GUIを開発しています。XAML- <TabControl>タグに画像を追加するには

現在、いくつかのタブが表示されていますが、それぞれのアプリケーションのさまざまな側面が表示されています。

アプリケーションの「接続ステータス」をリモートサーバーに表示するアイコンが2つあります(アプリケーションがサーバーに接続されている場合は1つのイメージが表示され、接続されていない場合は別のイメージが表示されます)。これらの画像は現在、タブ付きディスプレイの1つに表示されていますが、アプリケーションウィンドウの一番右にあるタブバーに移動したいので、タブに関係なく常に表示されます。ユーザーは現在閲覧中です。

<Grid> 
    <TabControl ...> 
     <TabItem> 
      ... 
     </TabItem> 
     <TabItem ...> 
      <StackPanel> 
       <Grid> 
        ... 
        <Image ... /> 
        <Image ... /> 
       </Grid> 
      </StackPanel> 
     </TabItem> 
    </TabControl> 
</Grid> 

基本的には、<Image>タグ内の画像の一つは、アプリケーションがサーバーに接続されていることを示すために表示され、他の画像を示すために表示されます。

私のXAMLは、現在、このように構成されていますアプリケーションがサーバーに接続されていないことを確認します。それらはアプリケーション内の同じ場所に配置されており、アプリケーションがサーバーに接続されているかどうかをチェックし、メソッドが返す値に基づいて適切なイメージを表示するメソッドがあります。

私がやりたいことは、<Image>タグをメインの<TabControl>タグに移動することです。これらの画像は 'タブメニュー'に表示されますが、ウィンドウの右端に表示されます左端に表示されます)。これは、ユーザが現在どのタブを見ていてもそれらの画像が表示されることを意味する。

私はこれを行う方法がありますか?私は<TabControl>タグの中に直接<Image>タグを追加しようとしましたが、アプリケーションを実行すると画像が表示されません...私はここで何をしようとしていますか?虚TabBarのを追加するには

答えて

2

、あなたはTabControlTemplateRowDefinition新しいを作成する必要があります。例を示しましょう:

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="WpfApplication2.MainWindow" 
    Title="MainWindow" Height="350" Width="525"> 
<Window.Resources> 
    <SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/> 
    <SolidColorBrush x:Key="TabItem.Selected.Border" Color="#ACACAC"/> 
    <Style x:Key="TabControlStyle1" TargetType="{x:Type TabControl}"> 
     <Setter Property="Padding" Value="2"/> 
     <Setter Property="HorizontalContentAlignment" Value="Center"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Background" Value="{StaticResource TabItem.Selected.Background}"/> 
     <Setter Property="BorderBrush" Value="{StaticResource TabItem.Selected.Border}"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type TabControl}"> 
        <Grid x:Name="templateRoot" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local"> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition x:Name="ColumnDefinition0"/> 
          <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/> 
         </Grid.ColumnDefinitions> 
         <Grid.RowDefinitions> 
          <RowDefinition x:Name="RowDefinition0" Height="Auto"/> 
          <RowDefinition x:Name="RowDefinition2" Height="0.1*"/> 
          <RowDefinition x:Name="RowDefinition1" Height="*"/> 
         </Grid.RowDefinitions> 
         <TabPanel x:Name="headerPanel" Background="Yellow" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/> 
         <StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="RightToLeft"> 
          <Image Source="/Images/1.png" /> 
          <Image Source="/Images/2.png" /> 
          <Image Source="/Images/3.png" />         
         </StackPanel> 
         <Border x:Name="contentPanel" BorderBrush="Green" BorderThickness="5" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="2" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local"> 
          <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
         </Border> 
        </Grid> 
        <ControlTemplate.Triggers> 
         <Trigger Property="TabStripPlacement" Value="Bottom"> 
          <Setter Property="Grid.Row" TargetName="headerPanel" Value="1"/> 
          <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/> 
          <Setter Property="Height" TargetName="RowDefinition0" Value="*"/> 
          <Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/> 
          <Setter Property="Margin" TargetName="headerPanel" Value="2,0,2,2"/> 
         </Trigger> 
         <Trigger Property="TabStripPlacement" Value="Left"> 
          <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/> 
          <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/> 
          <Setter Property="Grid.Column" TargetName="headerPanel" Value="0"/> 
          <Setter Property="Grid.Column" TargetName="contentPanel" Value="1"/> 
          <Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/> 
          <Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/> 
          <Setter Property="Height" TargetName="RowDefinition0" Value="*"/> 
          <Setter Property="Height" TargetName="RowDefinition1" Value="0"/> 
          <Setter Property="Margin" TargetName="headerPanel" Value="2,2,0,2"/> 
         </Trigger> 
         <Trigger Property="TabStripPlacement" Value="Right"> 
          <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/> 
          <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/> 
          <Setter Property="Grid.Column" TargetName="headerPanel" Value="1"/> 
          <Setter Property="Grid.Column" TargetName="contentPanel" Value="0"/> 
          <Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/> 
          <Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/> 
          <Setter Property="Height" TargetName="RowDefinition0" Value="*"/> 
          <Setter Property="Height" TargetName="RowDefinition1" Value="0"/> 
          <Setter Property="Margin" TargetName="headerPanel" Value="0,2,2,2"/> 
         </Trigger> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
    <Style x:Key="FooTabControl" TargetType="{x:Type TabControl}"> 
     <!--This style is intended to be empty just for show that you can declare as many styles as you want--> 
    </Style> 
    <Style x:Key="FooButton" TargetType="{x:Type Button}"> 
     <!--This style is intended to be empty just for show that you can declare as many styles as you want--> 
    </Style> 
</Window.Resources> 
<Grid Name="grid"> 
    <TabControl Style="{DynamicResource TabControlStyle1}"> 
     <TabItem Header="1">1</TabItem> 
     <TabItem Header="2">2</TabItem> 
     <TabItem Header="3">3</TabItem> 
    </TabControl> 
</Grid> 
</Window> 
+0

お返事ありがとうございます。つまり、画像を1つの '' Header'に表示したくないのですが、それらをトップレベルの ''に表示して、それらが 'タブバーに表示されるようにしたいのです'ユーザーが現在表示しているタブに関係なく。たとえば、アプリケーションウィンドウで3つのタブが開いている場合、これらは「タブバー」の左側に表示され、ユーザーはクリックすることで表示するものを選択することができます。どのタブが選択されているかによって更新されます。 – someone2088

+0

私がしたいことは、これらの画像を 'タブバー'の右側に追加することで、ユーザーが現在選択しているタブに関係なく常に表示されるようになります。アプリケーションの1つの特定の側面に関連するだけではありません。 – someone2088

+0

お世話になりました。ありがとうございました。しかし、私はすでに'を追加しようとすると、XMLに ' ''Value'プロパティが複数回設定されている」というエラーをコンパイルするか、または書いたコードをすべて追加すると、必要な画像が表示されますが、残りのコンテンツは停止します。が表示されていましたが、VSのデザインビューで「 – someone2088

関連する問題