Skip to content

Commit b4dbaf1

Browse files
committed
Migrate repository
1 parent 3a5b9b0 commit b4dbaf1

File tree

142 files changed

+11679
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+11679
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<UseWPF>true</UseWPF>
6+
<ApplicationIcon>logo.ico</ApplicationIcon>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Page Update="Themes\Generic.xaml">
11+
<SubType>Designer</SubType>
12+
<Generator>MSBuild:Compile</Generator>
13+
</Page>
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using System.Windows.Input;
5+
6+
namespace BionicCode.Controls.Net.Core.Wpf
7+
{
8+
/// <summary>
9+
/// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
10+
///
11+
/// Step 1a) Using this custom control in a XAML file that exists in the current project.
12+
/// Add this XmlNamespace attribute to the root element of the markup file where it is
13+
/// to be used:
14+
///
15+
/// xmlns:MyNamespace="clr-namespace:WpfTestRange.Main"
16+
///
17+
///
18+
/// Step 1b) Using this custom control in a XAML file that exists in a different project.
19+
/// Add this XmlNamespace attribute to the root element of the markup file where it is
20+
/// to be used:
21+
///
22+
/// xmlns:MyNamespace="clr-namespace:WpfTestRange.Main;assembly=WpfTestRange.Main"
23+
///
24+
/// You will also need to add a project reference from the project where the XAML file lives
25+
/// to this project and Rebuild to avoid compilation errors:
26+
///
27+
/// Right click on the target project in the Solution Explorer and
28+
/// "Add Reference"->"Projects"->[Browse to and select this project]
29+
///
30+
///
31+
/// Step 2)
32+
/// Go ahead and use your control in the XAML file.
33+
///
34+
/// <MyNamespace:ClosableTabControl/>
35+
///
36+
/// </summary>
37+
public class ClosableTabControl : TabControl
38+
{
39+
public static readonly RoutedUICommand CloseTabRoutedCommand = new RoutedUICommand(
40+
"Close TabItem and remove item from ItemsSource",
41+
nameof(ClosableTabControl.CloseTabRoutedCommand),
42+
typeof(ClosableTabControl));
43+
44+
static ClosableTabControl()
45+
{
46+
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(ClosableTabControl), new FrameworkPropertyMetadata(typeof(ClosableTabControl)));
47+
}
48+
49+
public ClosableTabControl()
50+
{
51+
this.CommandBindings.Add(
52+
new CommandBinding(ClosableTabControl.CloseTabRoutedCommand, ExecuteRemoveTab, CanExecuteRemoveTab));
53+
}
54+
55+
private void CanExecuteRemoveTab(object sender, CanExecuteRoutedEventArgs e)
56+
{
57+
e.CanExecute = e.OriginalSource is FrameworkElement frameworkElement
58+
&& this.Items.Contains(frameworkElement.DataContext)
59+
|| this.Items.Contains(e.Source);
60+
}
61+
62+
private void ExecuteRemoveTab(object sender, ExecutedRoutedEventArgs e)
63+
{
64+
object tabItemToRemove = this.ItemsSource == null
65+
? e.Source
66+
: (e.OriginalSource as FrameworkElement).DataContext;
67+
int lastItemIndex = this.Items.Count - 1;
68+
int nextItemIndex = this.Items.IndexOf(tabItemToRemove) + 1;
69+
this.SelectedIndex = Math.Min(lastItemIndex, nextItemIndex);
70+
(this.ItemContainerGenerator.ContainerFromItem(tabItemToRemove) as UIElement).Visibility = Visibility.Collapsed;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)