55using System ;
66using System . Collections . Generic ;
77using System . Collections . ObjectModel ;
8+ using System . ComponentModel ;
89using System . IO ;
910using System . Linq ;
11+ using System . Reflection ;
1012using System . Text ;
1113using System . Threading . Tasks ;
1214using System . Windows ;
@@ -26,139 +28,39 @@ namespace INIManagerProject.View
2628 public partial class MainWindow : Window
2729 {
2830 private MainWindowViewModel _mainWindowViewModel ;
31+ private readonly FieldInfo _menuDropAlignmentField ;
2932 MainWindowViewModel MainWindowViewModel => _mainWindowViewModel ;
3033
3134 public MainWindow ( )
3235 {
3336 try
3437 {
38+ _menuDropAlignmentField = typeof ( SystemParameters ) . GetField ( "_menuDropAlignment" , BindingFlags . NonPublic | BindingFlags . Static ) ;
39+ System . Diagnostics . Debug . Assert ( _menuDropAlignmentField != null ) ;
40+ EnsureStandardPopupAlignment ( ) ;
41+ SystemParameters . StaticPropertyChanged += SystemParameters_StaticPropertyChanged ;
42+
3543 _mainWindowViewModel = new MainWindowViewModel ( ) ;
3644 DataContext = _mainWindowViewModel ;
3745 InitializeComponent ( ) ;
38-
39-
40- // initialize tabItem array
41-
42- //New stuff
43-
44-
45- // add a tabItem with + in header
46- //TabItem tabAdd = new TabItem();
47- //tabAdd.Header = "+";
48-
49- // _tabItems.Add(tabAdd);
50-
51- // add first tab
52- //this.AddTabItem();
53-
54- // bind tab control
55- //tabControl.DataContext = _tabItems;
56-
57- //tabControl.SelectedIndex = 0;
5846 }
5947 catch ( Exception ex )
6048 {
6149 MessageBox . Show ( ex . Message ) ;
6250 }
6351 }
64-
65- // Should not be needed.
66- private TabItem AddTabItem ( )
52+ private void SystemParameters_StaticPropertyChanged ( object sender , PropertyChangedEventArgs e )
6753 {
68- /*int count = _tabItems.Count;
69-
70- // create new tab item
71- TabItem tab = new TabItem();
72- tab.Header = string.Format("DocumentName {0}", count);
73- tab.Name = string.Format("tab{0}", count);
74- tab.HeaderTemplate = tabControl.FindResource("TabHeader") as DataTemplate;
75-
76- // add controls to tab item, this case I added just a textbox
77- TextBox txt = new TextBox();
78- txt.Name = "txt";
79- DocumentView dv = new DocumentView();
80- tab.Content = dv;
81-
82- // insert tab item right before the last (+) tab item
83- _tabItems.Insert(count -1, tab);
84- return tab;*/
85- return null ;
86- }
87-
88- // Should not be needed.
89- private void document_SelectionChanged ( object sender , SelectionChangedEventArgs e )
90- {
91- /*TabItem tab = tabControl.SelectedItem as TabItem;
92-
93- if (tab != null && tab.Header != null)
94- {
95- if (tab.Header.Equals("+"))
96- {
97- // clear tab control binding
98- tabControl.DataContext = null;
99-
100- // add new tab
101- TabItem newTab = this.AddTabItem();
102-
103- // bind tab control
104- tabControl.DataContext = _tabItems;
105-
106- // select newly added tab item
107- tabControl.SelectedItem = newTab;
108- }
109- else
110- {
111- // your code here...
112- }
113- }*/
54+ EnsureStandardPopupAlignment ( ) ;
11455 }
11556
116- //private void btnCloseTab_Click(object sender, RoutedEventArgs e)
117- //{
118- /*if (sender is Button button)
119- {
120- var docName = button.Tag;
121- Document docToClose = _mainWindowViewModel.DocumentManager.DocumentList.Single(d => d.DocumentName == docName);
122- docToClose.Persist();
123- ((ObservableCollection<Document>) documentTabControl.ItemsSource).Remove(docToClose);
124- }*/
125-
126- //string tabName = (sender as Button).CommandParameter.ToString();
127-
128- /*
129- var item = tabControl.Items.Cast<TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();
130-
131- TabItem tab = item as TabItem;
132-
133- if (tab != null)
57+ private void EnsureStandardPopupAlignment ( )
58+ {
59+ if ( SystemParameters . MenuDropAlignment && _menuDropAlignmentField != null )
13460 {
135- if (_tabItems.Count < 3)
136- {
137- MessageBox.Show("Cannot remove last tab.");
138- }
139- else if (MessageBox.Show(string.Format("Are you sure you want to remove the tab '{0}'?", tab.Header.ToString()),
140- "Remove Tab", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
141- {
142- // get selected tab
143- TabItem selectedTab = tabControl.SelectedItem as TabItem;
144-
145- // clear tab control binding
146- tabControl.DataContext = null;
147-
148- _tabItems.Remove(tab);
149-
150- // bind tab control
151- tabControl.DataContext = _tabItems;
152-
153- // select previously selected tab. if that is removed then select first tab
154- if (selectedTab == null || selectedTab.Equals(tab))
155- {
156- selectedTab = _tabItems[0];
157- }
158- tabControl.SelectedItem = selectedTab;
159- }
61+ _menuDropAlignmentField . SetValue ( null , false ) ;
16062 }
161- }*/
63+ }
16264
16365 private void mnuOpen_Click ( object sender , RoutedEventArgs e )
16466 {
0 commit comments