Skip to content

WPF-55869 - Appearance Customization sample updated. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions AppearanceCustomization_2010.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Helper\SubjectToImageSourceConverter.cs" />
<Compile Include="Helper\ImageTemplateSelector.cs" />
<Compile Include="ViewModel\SchedulerViewModel.cs" />
<Page Include="Helper\SubjectImagePaths.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -106,12 +110,6 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\cake_schedule.png" />
<Resource Include="Images\Conference_schedule.png" />
<Resource Include="Images\Stethoscope.png" />
<Resource Include="Images\Troubleshoot.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="App.ico" />
</ItemGroup>
Expand Down
41 changes: 41 additions & 0 deletions Helper/ImageTemplateSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace AppearanceCustomization
{
public class ImageTemplateSelector : IValueConverter
{
static ResourceDictionary myResourceDictionary;
/// <summary>
/// Initializes a new instance of the <see cref="ImageTemplateSelector" /> class.
/// </summary>
static ImageTemplateSelector()
{
myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source =
new Uri("/AppointmentCustomization;component/Helper/SubjectImagePaths.xaml",
UriKind.RelativeOrAbsolute);
}

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string imageName = value.ToString().Replace(" ", "").ToLower();
DataTemplate dataTemplateImagePaths;
dataTemplateImagePaths = myResourceDictionary[imageName] as DataTemplate;
if (dataTemplateImagePaths != null)
return dataTemplateImagePaths;
else
return myResourceDictionary["default"] as DataTemplate;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
198 changes: 198 additions & 0 deletions Helper/SubjectImagePaths.xaml

Large diffs are not rendered by default.

30 changes: 0 additions & 30 deletions Helper/SubjectToImageSourceConverter.cs

This file was deleted.

Binary file removed Images/Conference_schedule.png
Binary file not shown.
Binary file removed Images/Stethoscope.png
Binary file not shown.
Binary file removed Images/Troubleshoot.png
Binary file not shown.
Binary file removed Images/cake_schedule.png
Binary file not shown.
89 changes: 45 additions & 44 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,72 +24,73 @@
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

<local:SubjectToImageSourceConverter x:Key="subjectToImageConverter"/>
<local:ImageTemplateSelector x:Key="imageTemplateSelector"/>

<DataTemplate x:Key="appointmentTemplate">
<StackPanel Background="{Binding Background}"
<StackPanel Background="{Binding Data.Background}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Orientation="Horizontal">
<Image x:Name="Image"
<Label x:Name="Image"
VerticalAlignment="Center"
Height="30"
Width="15"
Margin="5,0"
Source="{Binding Converter={StaticResource subjectToImageConverter}, Path=EventName}">
</Image>
<TextBlock Margin="5"
Width="30"
HorizontalContentAlignment="Right"
Margin="2,0,0,0"
ContentTemplate="{Binding Data.EventName, Converter={StaticResource imageTemplateSelector}}">
</Label>
<TextBlock Margin="2"
VerticalAlignment="Center"
Text="{Binding EventName}"
Text="{Binding Data.EventName}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap"
FontSize="12"
TextAlignment="Left"
FontWeight="Bold"/>
FontStyle="Italic"/>
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="allDayAppointmentTemplate">
<StackPanel Background="{Binding Background}"
<StackPanel Background="{Binding Data.Background}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Orientation="Horizontal">
<Image x:Name="Image"
VerticalAlignment="Top"
Height="20"
Width="15"
Margin="5,2,0,0"
Source="{Binding Converter={StaticResource subjectToImageConverter}, Path=EventName}">
</Image>
<TextBlock Margin="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Text="{Binding EventName}"
<Label x:Name="Image"
VerticalAlignment="Center"
Width="30" Margin="2,0,0,0"
HorizontalAlignment="Right"
ContentTemplate="{Binding Data.EventName, Converter={StaticResource imageTemplateSelector}}">
</Label>
<TextBlock Margin="2"
VerticalAlignment="Center"
Text="{Binding Data.EventName}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap"
FontWeight="SemiBold"/>
</StackPanel>
TextWrapping="Wrap"
FontSize="12"
TextAlignment="Left"
FontStyle="Italic"/>
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="monthAppointmentTemplate">
<StackPanel Background="{Binding Background}"
VerticalAlignment="Stretch"
<StackPanel Background="{Binding Data.Background}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Orientation="Horizontal">
<Image x:Name="Image"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Height="12"
Width="15"
Margin="5,2,0,0"
Source="{Binding Converter={StaticResource subjectToImageConverter}, Path=EventName}">
</Image>
<TextBlock Margin="5,2,0,0"
FontSize="10"
HorizontalAlignment="Stretch"
Text="{Binding EventName}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap"
FontWeight="Heavy"/>
<Label x:Name="Image"
VerticalAlignment="Center"
Width="30"
HorizontalAlignment="Right"
Margin="2,0,0,0"
ContentTemplate="{Binding Data.EventName, Converter={StaticResource imageTemplateSelector}}">
</Label>
<TextBlock Margin="2"
VerticalAlignment="Center"
Text="{Binding Data.EventName}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap"
FontSize="12"
TextAlignment="Left"
FontStyle="Italic"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
Expand Down Expand Up @@ -125,7 +126,7 @@
<StackPanel
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,20,25,0">
Margin="0,10,25,0">
<ComboBox x:Name="viewTypeComboBox" ItemsSource="{Binding Source={StaticResource schedulerViewTypes}}"
SelectedIndex="2" Width="100"/>
</StackPanel>
Expand Down
28 changes: 13 additions & 15 deletions ViewModel/SchedulerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ private void AddAppointments()
var day = random.Next(1, 30);
var hour = random.Next(9, 14);
var newEvent = new Events();
newEvent.EventName = this.eventCollection[random.Next(0, 4)];
newEvent.EventName = this.eventCollection[random.Next(0, 9)];
newEvent.From = new DateTime(year, month, day, hour, 0, 0);
newEvent.To = newEvent.From.AddHours(1);
newEvent.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.colorCollection[random.Next(0, 15)]));
newEvent.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.colorCollection[random.Next(0, 8)]));
this.Appointments.Add(newEvent);
}

for (int i = 0; i < 6; i++)
{
var allDayEvent = new Events();
allDayEvent.EventName = this.eventCollection[random.Next(0, 5)];
allDayEvent.EventName = this.eventCollection[random.Next(0, 9)];
allDayEvent.From = this.startTimeCollection[random.Next(0,10)];
allDayEvent.To = allDayEvent.From.AddHours(1);
allDayEvent.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.colorCollection[random.Next(0, 15)]));
allDayEvent.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.colorCollection[random.Next(0, 8)]));
allDayEvent.IsAllDay = true;
this.Appointments.Add(allDayEvent);
}
Expand All @@ -93,10 +93,15 @@ private void InitializingDataForEvents()
{
this.eventCollection = new List<string>();
this.eventCollection.Add("Conference");
this.eventCollection.Add("System Troubleshoot");
this.eventCollection.Add("Birthday");
this.eventCollection.Add("Checkup");
this.eventCollection.Add("Business Meeting");
this.eventCollection.Add("Conference");
this.eventCollection.Add("Medical check up");
this.eventCollection.Add("Consulting");
this.eventCollection.Add("Project Status Discussion");
this.eventCollection.Add("Client Meeting");
this.eventCollection.Add("General Meeting");
this.eventCollection.Add("Yoga Therapy");
this.eventCollection.Add("GoToMeeting");

this.startTimeCollection = new List<DateTime>();
this.startTimeCollection.Add(DateTime.Now.Date.AddHours(10));
Expand Down Expand Up @@ -126,15 +131,8 @@ private void InitializingDataForEvents()
this.colorCollection.Add("#FFF09609");
this.colorCollection.Add("#FF339933");
this.colorCollection.Add("#FF00ABA9");
this.colorCollection.Add("#FFE671B8");
this.colorCollection.Add("#FF1BA1E2");
this.colorCollection.Add("#FFD80073");
this.colorCollection.Add("#FFA2C139");
this.colorCollection.Add("#4F67FF");
this.colorCollection.Add("#FFA2C139");
this.colorCollection.Add("#FFD80073");
this.colorCollection.Add("#FF339933");
this.colorCollection.Add("#FFE671B8");
this.colorCollection.Add("#FF00ABA9");
}
#endregion
}
Expand Down