2010-11-09 71 views

回答

0

看看下面的鏈接,它解釋瞭如何自定義選項卡控件以在選項卡中添加更多內容。我會將一個圖像按鈕添加到選項卡標題並關聯一個單擊事件以關閉它。

http://www.c-sharpcorner.com/UploadFile/mahesh/SilverlightTabControl07022008170702PM/SilverlightTabControl.aspx

下面是一個示例

<Grid x:Name="LayoutRoot" Background="White"> 
    <sdk:TabControl Height="100" HorizontalAlignment="Left" Margin="108,94,0,0" Name="tabControl1" VerticalAlignment="Top" Width="200"> 
     <sdk:TabItem Name="tabItem1"> 
      <sdk:TabItem.Header> 
       <StackPanel Orientation="Horizontal"> 
        <TextBlock Text="Polygon" Margin="1,1,1,1" VerticalAlignment="Center" /> 
        <Button Content="X" Click="Button_Click"/> 
       </StackPanel> 
      </sdk:TabItem.Header> 
      <Grid /> 
     </sdk:TabItem> 
    </sdk:TabControl> 
</Grid> 
1

看到它:輸入這個代碼在用戶控件

<Style TargetType='sdk:TabItem'> 
     <Setter Property='HeaderTemplate'> 
      <Setter.Value> 
       <DataTemplate> 
        <StackPanel Orientation='Horizontal' 
              Background='Transparent'> 
         <TextBlock Text='{Binding}' /> 
         <!--<Button Command="{Binding RemoveItemCommand}" VerticalAlignment='Center' 
             Style="{StaticResource CloseButton}" 
             Margin="5,0,0,0" 
             Content="M0,0 L6,6 M6, 0 L0,6" 
             ToolTipService.ToolTip="Remove item" />--> 
         <Button x:Name='btnCloaseTab' 
             Click='btnCloaseTab_Click' 
             VerticalAlignment='Center' 
             Style="{StaticResource CloseButton}" 
             Margin="5,0,0,0" 
             Content="M0,0 L6,6 M6, 0 L0,6" 
             ToolTipService.ToolTip="بستن زبانه" /> 
        </StackPanel> 
       </DataTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
0
<Style x:Key="CloseButton" 
       TargetType="Button"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="Button"> 
        <Grid Background="Transparent" 
           Width="14" 
           Height="14"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal" /> 
           <VisualState x:Name="MouseOver"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" 
                            Storyboard.TargetName="FocusEllipse"> 
              <DiscreteObjectKeyFrame KeyTime="0"> 
               <DiscreteObjectKeyFrame.Value> 
                <Visibility>Visible</Visibility> 
               </DiscreteObjectKeyFrame.Value> 
              </DiscreteObjectKeyFrame> 
             </ObjectAnimationUsingKeyFrames> 
             <ColorAnimation Duration="0" 
                     To="#FFDC3030" 
                     Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" 
                     Storyboard.TargetName="FocusEllipse" /> 
             <ColorAnimation Duration="0" 
                     To="White" 
                     Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" 
                     Storyboard.TargetName="path" /> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Pressed"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" 
                            Storyboard.TargetName="FocusEllipse"> 
              <DiscreteObjectKeyFrame KeyTime="0"> 
               <DiscreteObjectKeyFrame.Value> 
                <Visibility>Visible</Visibility> 
               </DiscreteObjectKeyFrame.Value> 
              </DiscreteObjectKeyFrame> 
             </ObjectAnimationUsingKeyFrames> 
             <ColorAnimation Duration="0" 
                     To="Black" 
                     Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" 
                     Storyboard.TargetName="FocusEllipse" /> 
             <ColorAnimation Duration="0" 
                     To="White" 
                     Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" 
                     Storyboard.TargetName="path" /> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Disabled" /> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="FocusStates"> 
           <VisualState x:Name="Focused" /> 
           <VisualState x:Name="Unfocused" /> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Ellipse x:Name="FocusEllipse" 
             Fill="#FFF13535" 
             Visibility="Collapsed" /> 
         <Path x:Name="path" 
            Data="{TemplateBinding Content}" 
            Stroke="#FF898888" 
            HorizontalAlignment="Center" 
            VerticalAlignment="Center" 
            StrokeThickness="1" /> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
的資源