Click here to Skip to main content
15,887,361 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: need a coah for a WPF projet Pin
Abhinav S9-Sep-13 7:15
Abhinav S9-Sep-13 7:15 
QuestionVirtual classroom using silverlight Pin
Member 101834574-Sep-13 1:22
Member 101834574-Sep-13 1:22 
GeneralRe: Virtual classroom using silverlight Pin
Richard MacCutchan4-Sep-13 5:04
mveRichard MacCutchan4-Sep-13 5:04 
AnswerRe: Virtual classroom using silverlight Pin
Pete O'Hanlon4-Sep-13 5:45
mvePete O'Hanlon4-Sep-13 5:45 
QuestionWPF TreeView on a Windows 8 Tablet Pin
Kevin Marois3-Sep-13 6:56
professionalKevin Marois3-Sep-13 6:56 
AnswerRe: WPF TreeView on a Windows 8 Tablet Pin
Pete O'Hanlon3-Sep-13 10:12
mvePete O'Hanlon3-Sep-13 10:12 
GeneralRe: WPF TreeView on a Windows 8 Tablet Pin
Kevin Marois3-Sep-13 10:37
professionalKevin Marois3-Sep-13 10:37 
QuestionHow to avoid repeating dynamic tabitem at runtime? Pin
LAPEC2-Sep-13 15:07
LAPEC2-Sep-13 15:07 
Hello Everyone

I have created a small project in WPF. In this project I have a window with Menu Bar such as:
Administration, Explorers, Reports. Each of these menus have sub menus: for instance under Administration Menu-Bar there is a sub-menu called Users, and under Explorers Menu-Bar there is a sub-menu called Menu Categories.

My problem to my question is that on any of the sub-menus I click, it creates a dynamic tabitem and places them in the main tabcontrol (which this is fine), but if i click again on the same sub menus it repeats the same tabitems.
Can someone please help me solve this problem.

the source code for BackOfficeWindow.xaml.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using iPosCloud.com.iposcloud.config.uiC_;
using iPosCloud.com.iposcloud.bo.uiC_.explorer;
using iPosCloud.com.iposcloud.bo.uiC_.explorer.ViewModel;

namespace iPosCloud.com.iposcloud.bo.uiC_
{
    /// <summary>
    /// Interaction logic for BackOfficeWindow.xaml
    /// </summary>
    public partial class BackOfficeWindow : Window
    {
        private VMBackOfficeWindow vmBackOfficeWindow;

        public BackOfficeWindow()
        {
            InitializeComponent();
            // create an object of ViewModel as set it as DataContext
            vmBackOfficeWindow = new VMBackOfficeWindow();
            this.DataContext = vmBackOfficeWindow;
            ObservableCollectionTabItems = new ObservableCollection<VMParentForViews>();
        }

        public ObservableCollection<VMParentForViews> ObservableCollectionTabItems { get; set; }

        // ADMINISTRATION MENU
        private void menuItemAdminConfiguration_Click(object sender, RoutedEventArgs e)
        {
            RestaurantConfigurationView rcv = new RestaurantConfigurationView();
            //bow.Owner = this;
            rcv.ShowDialog();
            //this.Close();
        }

        #region "Close TabItems"

        private void menuItem1_Click(object sender, RoutedEventArgs e)
        {
            vmBackOfficeWindow.CloseTabItem(sender);
            menuUsers.IsEnabled = true;
            menuCategories.IsEnabled = true;
        }

        #endregion

        private void menuUsers_Click(object sender, RoutedEventArgs e)
        {
            this.vmBackOfficeWindow.AddTab("Users");
            menuUsers.IsEnabled = false;
        }

        // EXPLORERS MENU
        private void menuCategories_Click(object sender, RoutedEventArgs e)
        {
            this.vmBackOfficeWindow.AddTab("Category Explorer");

            menuCategories.IsEnabled = false;
        }
    }
}


and the source code for VMBackOfficeWindow.cs
C#
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Controls;

namespace iPosCloud.com.iposcloud.bo.uiC_.explorer.ViewModel
{
    public class VMBackOfficeWindow
    {
        private VMParentForViews vmParentForViews;

        public VMBackOfficeWindow()
        {
            ObservableCollectionTabItems = new ObservableCollection<VMParentForViews>();
        }

        public ObservableCollection<VMParentForViews> ObservableCollectionTabItems { get; set; }

        /// <summary>
        /// Adds the tab to the TabControl
        /// </summary>
        /// <param name="viewType">Type of the view.</param>
        public void AddTab(string viewType)
        {
            if(viewType.Equals("Users"))
            {
                vmParentForViews = new VMUserExplorer();
                this.ObservableCollectionTabItems.Add(vmParentForViews);
            }

            if(viewType.Equals("Category Explorer"))
            {
                vmParentForViews = new VMCategoryExplorer();
                this.ObservableCollectionTabItems.Add(vmParentForViews);
            }

            // Set the new tab to be the current tab
            ICollectionView collectionView1 = CollectionViewSource.GetDefaultView(this.ObservableCollectionTabItems);

            if (collectionView1 != null)
            {
                collectionView1.MoveCurrentTo(vmParentForViews);
            }
        }

        #region "Close TabItems"

        public void CloseTabItem(Object sender)
        {
            VMParentForViews vmParentForViews = (sender as MenuItem).DataContext as VMParentForViews;
            this.ObservableCollectionTabItems.Remove(vmParentForViews);
        }

        #endregion
    }
}


kind regards

roni
AnswerRe: How to avoid repeating dynamic tabitem at runtime? Pin
Pete O'Hanlon2-Sep-13 19:25
mvePete O'Hanlon2-Sep-13 19:25 
GeneralRe: How to avoid repeating dynamic tabitem at runtime? Pin
LAPEC3-Sep-13 1:46
LAPEC3-Sep-13 1:46 
GeneralRe: How to avoid repeating dynamic tabitem at runtime? Pin
Pete O'Hanlon3-Sep-13 2:02
mvePete O'Hanlon3-Sep-13 2:02 
GeneralRe: How to avoid repeating dynamic tabitem at runtime? Pin
LAPEC3-Sep-13 3:12
LAPEC3-Sep-13 3:12 
GeneralRe: How to avoid repeating dynamic tabitem at runtime? Pin
Pete O'Hanlon3-Sep-13 3:59
mvePete O'Hanlon3-Sep-13 3:59 
QuestionMVVM pattern Pin
columbos1492731-Aug-13 18:46
columbos1492731-Aug-13 18:46 
AnswerRe: MVVM pattern Pin
SledgeHammer013-Sep-13 9:56
SledgeHammer013-Sep-13 9:56 
GeneralRe: Prism Quick Starts Pin
NotPolitcallyCorrect30-Aug-13 4:29
NotPolitcallyCorrect30-Aug-13 4:29 
QuestionHow to force refresh of images being cached in Silverlight Deep Zoom app? Pin
Member 297027028-Aug-13 6:04
Member 297027028-Aug-13 6:04 
AnswerRe: How to force refresh of images being cached in Silverlight Deep Zoom app? Pin
Jason Gleim28-Aug-13 7:49
professionalJason Gleim28-Aug-13 7:49 
GeneralRe: How to force refresh of images being cached in Silverlight Deep Zoom app? Pin
Member 297027028-Aug-13 8:14
Member 297027028-Aug-13 8:14 
GeneralRe: How to force refresh of images being cached in Silverlight Deep Zoom app? Pin
Jason Gleim28-Aug-13 8:18
professionalJason Gleim28-Aug-13 8:18 
GeneralRe: How to force refresh of images being cached in Silverlight Deep Zoom app? Pin
Member 297027028-Aug-13 8:44
Member 297027028-Aug-13 8:44 
GeneralRe: How to force refresh of images being cached in Silverlight Deep Zoom app? Pin
Jason Gleim28-Aug-13 8:54
professionalJason Gleim28-Aug-13 8:54 
QuestionCan someone explain this PRISM concept? Pin
SledgeHammer0127-Aug-13 8:39
SledgeHammer0127-Aug-13 8:39 
QuestionAssign a null value to DateTime property Pin
maxRazar26-Aug-13 21:00
maxRazar26-Aug-13 21:00 
AnswerRe: Assign a null value to DateTime property Pin
Pete O'Hanlon26-Aug-13 23:02
mvePete O'Hanlon26-Aug-13 23:02 

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.