Click here to Skip to main content
15,888,323 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: can't edit tabitem Pin
david131324-Jul-11 8:26
david131324-Jul-11 8:26 
GeneralRe: can't edit tabitem Pin
Mark Salsbery24-Jul-11 8:28
Mark Salsbery24-Jul-11 8:28 
QuestionClosable Tabs Pin
jgalak23-Jul-11 8:03
jgalak23-Jul-11 8:03 
AnswerRe: Closable Tabs Pin
SledgeHammer0123-Jul-11 11:42
SledgeHammer0123-Jul-11 11:42 
GeneralRe: Closable Tabs Pin
jgalak23-Jul-11 14:48
jgalak23-Jul-11 14:48 
GeneralRe: Closable Tabs Pin
SledgeHammer0123-Jul-11 15:01
SledgeHammer0123-Jul-11 15:01 
GeneralRe: Closable Tabs Pin
Mark Salsbery23-Jul-11 15:36
Mark Salsbery23-Jul-11 15:36 
GeneralRe: Closable Tabs Pin
jgalak24-Jul-11 9:21
jgalak24-Jul-11 9:21 
Ok, I'm missing something here. I don't have a CloseableHeaders.g.cs file. All I have is CloseableHeader.xaml and CloseableHeader.xaml.cs

I'm posting the listings of the xaml and the two .cs files (is there a way to add an attachment on this forum?), but they are just copied from the tutorial with virtually no changes.

I'm starting to lean towards this being a namespace issue, as I want the namespace to be WGPM.Views, but as far as directory structure it's in WGPM\Views\BaseClasses

I'm using VS10, .Net 4.0, Win7/64.

CloseableHeader.xaml:
<UserControl x:Class="CloseableHeader"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="23" d:DesignWidth="81" Margin="0"
             xmlns:local="clr-namespace:WGPM.Views">
    <Grid>
        <Button Content="X"  Height="19" HorizontalAlignment="Right" Margin="0,3,4,0" Name="button_close" VerticalAlignment="Top" Width="20" FontFamily="Courier" FontWeight="Bold" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" FontStretch="Normal" Visibility="Visible" FontSize="14" Padding="0" ToolTip="Close"/>
        <Label Content="TabItem"  Height="23" HorizontalAlignment="Left" Margin="4,1,0,0" Name="label_TabTitle" VerticalAlignment="Top" FontFamily="Courier" FontSize="12" />
    </Grid>
</UserControl>


CloseableHeader.xamls.cs:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;


namespace WGPM.Views
{
    /// <summary>
    /// Interaction logic for CloseableItem.xaml
    /// </summary>
    public partial class CloseableHeader : UserControl
    {

        public CloseableHeader()
        {
            InitializeComponent();
        }
    }

}


ClosableTab.cs
using System;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;


namespace WGPM.Views
{
    class ClosableTab : TabItem
    {


        // Constructor
        public ClosableTab()
        {
            // Create an instance of the usercontrol
            CloseableHeader closableTabHeader = new CloseableHeader();

            // Assign the usercontrol to the tab header
            this.Header = closableTabHeader;

            // Attach to the CloseableHeader events (Mouse Enter/Leave, Button Click, and Label resize)
            closableTabHeader.button_close.MouseEnter += new MouseEventHandler(button_close_MouseEnter);
            closableTabHeader.button_close.MouseLeave += new MouseEventHandler(button_close_MouseLeave);
            closableTabHeader.button_close.Click += new RoutedEventHandler(button_close_Click);
            closableTabHeader.label_TabTitle.SizeChanged += new SizeChangedEventHandler(label_TabTitle_SizeChanged);
        }



        /// <summary>
        /// Property - Set the Title of the Tab
        /// </summary>
        public string Title
        {
            set
            {
                ((CloseableHeader)this.Header).label_TabTitle.Content = value;
            }
        }




        //
        // - - - Overrides  - - -
        //


        // Override OnSelected - Show the Close Button
        protected override void OnSelected(RoutedEventArgs e)
        {
            base.OnSelected(e);
            ((CloseableHeader)this.Header).button_close.Visibility = Visibility.Visible;
        }

        // Override OnUnSelected - Hide the Close Button
        protected override void OnUnselected(RoutedEventArgs e)
        {
            base.OnUnselected(e);
            ((CloseableHeader)this.Header).button_close.Visibility = Visibility.Hidden;
        }

        // Override OnMouseEnter - Show the Close Button
        protected override void OnMouseEnter(MouseEventArgs e)
        {
            base.OnMouseEnter(e);
            ((CloseableHeader)this.Header).button_close.Visibility = Visibility.Visible;
        }

        // Override OnMouseLeave - Hide the Close Button (If it is NOT selected)
        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            if (!this.IsSelected)
            {
                ((CloseableHeader)this.Header).button_close.Visibility = Visibility.Hidden;
            }
        }





        //
        // - - - Event Handlers  - - -
        //


        // Button MouseEnter - When the mouse is over the button - change color to Red
        void button_close_MouseEnter(object sender, MouseEventArgs e)
        {
            ((CloseableHeader)this.Header).button_close.Foreground = Brushes.Red;
        }

        // Button MouseLeave - When mouse is no longer over button - change color back to black
        void button_close_MouseLeave(object sender, MouseEventArgs e)
        {
            ((CloseableHeader)this.Header).button_close.Foreground = Brushes.Black;
        }


        // Button Close Click - Remove the Tab - (or raise an event indicating a "CloseTab" event has occurred)
        void button_close_Click(object sender, RoutedEventArgs e)
        {
            ((TabControl)this.Parent).Items.Remove(this);
        }


        // Label SizeChanged - When the Size of the Label changes (due to setting the Title) set position of button properly
        void label_TabTitle_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ((CloseableHeader)this.Header).button_close.Margin = new Thickness(((CloseableHeader)this.Header).label_TabTitle.ActualWidth + 5, 3, 4, 0);
        }





    }
}

GeneralRe: Closable Tabs Pin
Mark Salsbery24-Jul-11 9:26
Mark Salsbery24-Jul-11 9:26 
GeneralRe: Closable Tabs Pin
jgalak24-Jul-11 9:36
jgalak24-Jul-11 9:36 
GeneralRe: Closable Tabs Pin
Mark Salsbery24-Jul-11 9:41
Mark Salsbery24-Jul-11 9:41 
GeneralRe: Closable Tabs Pin
SledgeHammer0124-Jul-11 9:54
SledgeHammer0124-Jul-11 9:54 
GeneralRe: Closable Tabs Pin
Mark Salsbery24-Jul-11 11:17
Mark Salsbery24-Jul-11 11:17 
GeneralRe: Closable Tabs Pin
SledgeHammer0124-Jul-11 9:52
SledgeHammer0124-Jul-11 9:52 
GeneralRe: Closable Tabs Pin
jgalak27-Jul-11 14:31
jgalak27-Jul-11 14:31 
QuestionSimple and good way to Windows application development using C# + WPF + MVVC + prism 4 ? Pin
Manjeet patel22-Jul-11 3:15
Manjeet patel22-Jul-11 3:15 
AnswerRe: Simple and good way to Windows application development using C# + WPF + MVVC + prism 4 ? Pin
Ian Shlasko22-Jul-11 3:37
Ian Shlasko22-Jul-11 3:37 
GeneralRe: Simple and good way to Windows application development using C# + WPF + MVVC + prism 4 ? Pin
Manjeet patel22-Jul-11 3:48
Manjeet patel22-Jul-11 3:48 
AnswerRe: Simple and good way to Windows application development using C# + WPF + MVVC + prism 4 ? Pin
Abhinav S22-Jul-11 4:05
Abhinav S22-Jul-11 4:05 
AnswerRe: Simple and good way to Windows application development using C# + WPF + MVVC + prism 4 ? Pin
Richard MacCutchan22-Jul-11 4:25
mveRichard MacCutchan22-Jul-11 4:25 
QuestionScrolling in nested Listbox WPF Pin
Phantom1322-Jul-11 0:29
Phantom1322-Jul-11 0:29 
AnswerRe: Scrolling in nested Listbox WPF Pin
teejayem30-Jul-11 12:44
teejayem30-Jul-11 12:44 
QuestionSplash Screen in WPF Browser APP Pin
vonb21-Jul-11 1:21
vonb21-Jul-11 1:21 
AnswerRe: Splash Screen in WPF Browser APP Pin
vonb21-Jul-11 4:33
vonb21-Jul-11 4:33 
QuestionStyle.TargetType = Interface || abstract class Pin
ezazazel19-Jul-11 22:44
ezazazel19-Jul-11 22:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.