Skip to content

Commit 5279e2e

Browse files
authored
Sample for expand or collapse the Taskbar programmatically using the MVVM pattern is added
1 parent 1c9ba4f commit 5279e2e

19 files changed

Lines changed: 800 additions & 0 deletions

TaskBar_MVVM/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
5+
</startup>
6+
</configuration>

TaskBar_MVVM/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="Taskbar_Mvvm.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:Taskbar_Mvvm"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

TaskBar_MVVM/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace Taskbar_Mvvm
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
70.5 KB
Loading
66.6 KB
Loading
67.5 KB
Loading

TaskBar_MVVM/MainWindow.xaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<Window
2+
x:Class="Taskbar_Mvvm.MainWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
7+
xmlns:i2="http://schemas.microsoft.com/expression/2010/interactivity"
8+
xmlns:local="clr-namespace:Taskbar_Mvvm"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
11+
Title="TaskBar_customization"
12+
Width="800"
13+
Height="450"
14+
WindowStartupLocation="CenterScreen"
15+
mc:Ignorable="d">
16+
<Window.DataContext>
17+
<local:TaskBarViewModel />
18+
</Window.DataContext>
19+
20+
<Window.Resources>
21+
<DataTemplate x:Key="DefaultTemplate">
22+
<StackPanel>
23+
<TextBlock Text="Default content" />
24+
</StackPanel>
25+
</DataTemplate>
26+
<DataTemplate x:Key="NormalTemplate">
27+
<Grid>
28+
<Grid.ColumnDefinitions>
29+
<ColumnDefinition/>
30+
<ColumnDefinition/>
31+
</Grid.ColumnDefinitions>
32+
<StackPanel Margin="5">
33+
<TextBlock Margin="2" Text="{Binding Name}" />
34+
<TextBlock Margin="2" Text="{Binding DateOfBirth}" />
35+
<TextBlock Margin="2" Text="{Binding Geneder}" />
36+
<TextBlock Margin="2" Text="{Binding DateOfJoining}"/>
37+
</StackPanel>
38+
<StackPanel Grid.Column="1" Margin="5">
39+
<TextBlock
40+
Margin="2"
41+
HorizontalAlignment="Center"
42+
VerticalAlignment="Center">
43+
Employee Photo
44+
</TextBlock>
45+
<Image
46+
Margin="2"
47+
Height="100"
48+
VerticalAlignment="Top"
49+
Source="{Binding ImageSource}" />
50+
</StackPanel>
51+
</Grid>
52+
</DataTemplate>
53+
<local:PremiumUserDataTemplateSelector
54+
x:Key="TaskBarContentTemplateSelector"
55+
DefaultTemplate="{StaticResource DefaultTemplate}"
56+
NormalTemplate="{StaticResource NormalTemplate}" />
57+
</Window.Resources>
58+
<Grid>
59+
<syncfusion:TaskBar
60+
Name="taskBar"
61+
Width="500"
62+
Height="300"
63+
Margin="0,10,0,0"
64+
VerticalAlignment="Top"
65+
ScrollViewer.HorizontalScrollBarVisibility="Auto"
66+
ItemsSource="{Binding TaskBarItems}">
67+
<syncfusion:TaskBar.ItemContainerStyle>
68+
<Style TargetType="{x:Type syncfusion:TaskBarItem}">
69+
<Setter Property="Header" Value="{Binding Header}" />
70+
<Setter Property="syncfusion:TaskBar.IsOpened" Value="{Binding IsOpened}" />
71+
<Setter Property="ItemsSource" Value="{Binding TaskbarContentItems}" />
72+
<Setter Property="ItemContainerStyle">
73+
<!--ContentTemplateSelector used to set different content for each TaskBarItem-->
74+
<Setter.Value>
75+
<Style TargetType="ContentPresenter">
76+
<Setter Property="ContentTemplateSelector" Value="{StaticResource TaskBarContentTemplateSelector}" />
77+
</Style>
78+
</Setter.Value>
79+
</Setter>
80+
</Style>
81+
</syncfusion:TaskBar.ItemContainerStyle>
82+
</syncfusion:TaskBar>
83+
</Grid>
84+
</Window>

TaskBar_MVVM/MainWindow.xaml.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
using Syncfusion.Windows.Tools.Controls;
16+
using System.Reflection;
17+
using System.Windows.Interactivity;
18+
using Syncfusion.Windows.Shared;
19+
using Syncfusion.SfSkinManager;
20+
21+
namespace Taskbar_Mvvm
22+
{
23+
/// <summary>
24+
/// Interaction logic for MainWindow.xaml
25+
/// </summary>
26+
public partial class MainWindow : Window
27+
{
28+
public MainWindow()
29+
{
30+
SfSkinManager.SetTheme(this, new Theme("Office2019Colorful"));
31+
InitializeComponent();
32+
33+
}
34+
35+
}
36+
public class PremiumUserDataTemplateSelector : DataTemplateSelector
37+
{
38+
public DataTemplate DefaultTemplate { get; set; }
39+
public DataTemplate NormalTemplate { get; set; }
40+
public override DataTemplate SelectTemplate(object item, DependencyObject container)
41+
{
42+
FrameworkElement elemnt = container as FrameworkElement;
43+
// Set the different content for taskbaritem according your desire
44+
if ((item as Contentmodel).Name == "Content1")
45+
{
46+
return elemnt.FindResource("DefaultTemplate") as DataTemplate;
47+
}
48+
49+
return elemnt.FindResource("NormalTemplate") as DataTemplate;
50+
}
51+
}
52+
53+
}

TaskBar_MVVM/Model/TaskBarModel.cs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using Syncfusion.Windows.Shared;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Taskbar_Mvvm
10+
{
11+
public class TaskBarModel : NotificationObject
12+
{
13+
public string Header { get; set; }
14+
15+
16+
public TaskBarModel()
17+
{
18+
taskbarContentItems = new List<Contentmodel>();
19+
20+
}
21+
22+
private bool isOpen;
23+
24+
public bool IsOpened
25+
{
26+
get { return isOpen; }
27+
set
28+
{
29+
isOpen = value;
30+
this.RaisePropertyChanged(nameof (IsOpened));
31+
}
32+
}
33+
34+
35+
private int invokeParameter = 1;
36+
37+
public int InvokeParameter
38+
{
39+
get { return invokeParameter; }
40+
set { invokeParameter = value; RaisePropertyChanged("InvokeParameter"); }
41+
}
42+
43+
private List<Contentmodel> taskbarContentItems;
44+
45+
public List<Contentmodel> TaskbarContentItems
46+
{
47+
get { return taskbarContentItems; }
48+
set
49+
{
50+
taskbarContentItems = value;
51+
this.RaisePropertyChanged(nameof(TaskbarContentItems));
52+
}
53+
}
54+
}
55+
56+
57+
public class Contentmodel
58+
{
59+
private string name;
60+
public string Name
61+
{
62+
get
63+
{
64+
return name;
65+
}
66+
set { name = value; }
67+
}
68+
69+
private string dateOfBirth;
70+
public string DateOfBirth
71+
{
72+
get
73+
{
74+
return dateOfBirth;
75+
}
76+
set { dateOfBirth = value; }
77+
}
78+
79+
80+
private string gender;
81+
public string Geneder
82+
{
83+
get
84+
{
85+
return gender;
86+
}
87+
set { gender = value; }
88+
}
89+
90+
private string position;
91+
public string Position
92+
{
93+
get
94+
{
95+
return position;
96+
}
97+
set { position = value; }
98+
}
99+
100+
private string dateOfJoining;
101+
public string DateOfJoining
102+
{
103+
get
104+
{
105+
return dateOfJoining;
106+
}
107+
set { dateOfJoining = value; }
108+
}
109+
110+
111+
private string imageSource;
112+
public string ImageSource
113+
{
114+
get
115+
{
116+
return imageSource;
117+
}
118+
set { imageSource = value; }
119+
}
120+
}
121+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("Taskbar_Mvvm")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("Taskbar_Mvvm")]
15+
[assembly: AssemblyCopyright("Copyright © 2020")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)