Hi,
I want to do somenthing like you have in the example - ScheduleView - First Look. I will have several tabs (CustomViewDefinition), and a few of appointments. And when a click in a tab, i want to filter the appointments by the type of the game, ie, by the tab that i selected.
xaml:
MainPage.cs
ScheduleViewModel:
EncartesViewDefinition:
Etapa.cs:
My doubt is in function : private bool GroupFilterFunc(object groupName)!!
How do i apply the filter!!
Thanks
I want to do somenthing like you have in the example - ScheduleView - First Look. I will have several tabs (CustomViewDefinition), and a few of appointments. And when a click in a tab, i want to filter the appointments by the type of the game, ie, by the tab that i selected.
xaml:
<
schedule:RadScheduleView
Grid.Row
=
"1"
x:Name
=
"radScheduleView"
AppointmentsSource
=
"{Binding Appointments}"
Template
=
"{StaticResource RadScheduleViewControlTemplate}"
BorderBrush
=
"{x:Null}"
Background
=
"{StaticResource ScheduleViewBackground}"
>
</
schedule:RadScheduleView
>
MainPage.cs
private
void
FillScheduler()
{
ScheduleViewModel cal =
new
ScheduleViewModel();
radScheduleView.ViewDefinitions.AddRange(cal.GenerateViewsEncartes());
ResourceTypeCollection collectionTypeEncartes =
new
ResourceTypeCollection();
ResourceType encartes =
new
ResourceType(
"Games"
);
encartes.Resources.AddRange(cal.GenerateResources());
collectionTypeEncartes.Add(encartes);
radScheduleView.ResourceTypesSource = collectionTypeEncartes;
radScheduleView.DataContext =
new
ScheduleViewModel();
}
ScheduleViewModel:
public
class
ScheduleViewModel : ViewModelBase
{
private
Func<
object
,
bool
> groupFilter;
private
ObservableCollection<Etapa> appointments;
private
ObservableCollection<Resource> resources;
private
ObservableCollection<MonthViewDefinition> viewsDefinitions;
private
ObservableCollection<Category> categories;
public
ObservableCollection<Resource> Resources
{
get
{
return
this
.resources;
}
set
{
this
.resources = value;
}
}
public
ObservableCollection<Etapa> Appointments
{
get
{
return
this
.appointments;
}
set
{
this
.appointments = value;
}
}
public
ObservableCollection<MonthViewDefinition> ViewsDefinitions
{
get
{
return
this
.viewsDefinitions;
}
set
{
this
.viewsDefinitions = value;
}
}
public
ObservableCollection<Category> Categories
{
get
{
return
this
.categories;
}
set
{
this
.categories = value;
}
}
public
ScheduleViewModel()
{
//this.viewsDefinitions = this.GenerateViewsEncartes();
this
.categories =
this
.GenerateCategories();
//this.resources = this.GenerateResources();
this
.appointments =
this
.GenerateEvents();
this
.groupFilter =
new
Func<
object
,
bool
>(
this
.GroupFilterFunc);
}
public
ObservableCollection<Etapa> GenerateEvents()
{
RadScheduleView radScheduleView =
new
RadScheduleView();
ObservableCollection<Etapa> result =
new
ObservableCollection<Etapa>();
int
month = DateTime.Now.Month;
DateTime mondayDate = CalendarHelper.GetFirstDayOfWeek(DateTime.Today, DayOfWeek.Monday);
DateTime satDate = CalendarHelper.GetFirstDayOfWeek(DateTime.Today, DayOfWeek.Saturday);
DateTime lastsundayDate = CalendarHelper.GetEndOfMonth(DateTime.Today);
Etapa encarte1 =
new
Etapa();
encarte1.Subject =
"Tennis"
;
encarte1.Encarte =
"Tennis"
;
encarte1.Body =
""
;
encarte1.Category = FindCategory(categories,
"Validade"
);
encarte1.Start = mondayDate.AddHours(11).AddMinutes(15);
encarte1.End = mondayDate.AddHours(12).AddMinutes(20);
Resource etapa1 =
new
Resource();
etapa1.ResourceName =
"Tennis"
;
etapa1.ResourceType =
"Games"
;
encarte1.Resources.Add(etapa1);
result.Add(encarte1);
Etapa encarte2 =
new
Etapa();
encarte2.Encarte =
"Football"
;
encarte2.Subject =
"Football"
;
encarte2.Category = FindCategory(categories,
"Recebimento"
);
encarte2.Body =
""
;
encarte2.Start = mondayDate.AddHours(15);
encarte2.End = mondayDate.AddHours(16).AddMinutes(15);
Resource etapa2 =
new
Resource();
etapa2.ResourceName =
"Football"
;
etapa2.ResourceType =
"Games"
;
encarte2.Resources.Add(etapa2);
result.Add(encarte2);
Etapa encarte3 =
new
Etapa();
encarte3.Encarte =
"Golf"
;
encarte3.Subject =
"Golf"
;
encarte3.Category = FindCategory(categories,
"Recebimento"
);
encarte3.Body =
""
;
encarte3.Start = mondayDate.AddHours(15);
encarte3.End = mondayDate.AddHours(16).AddMinutes(15);
Resource etapa3 =
new
Resource();
etapa3.ResourceName =
"Golf"
;
etapa3.ResourceType =
"Games"
;
encarte3.Resources.Add(etapa3);
result.Add(encarte3);
return
result;
}
#region Generate Views (Encartes)
public
ObservableCollection<EncartesViewDefinition> GenerateViewsEncartes()
{
ObservableCollection<EncartesViewDefinition> result =
new
ObservableCollection<EncartesViewDefinition>();
EncartesViewDefinition encarte =
new
EncartesViewDefinition();
encarte.Title =
"Tennis"
;
encarte.GroupFilter = GroupFilter;
ResourceGroupDescription resourceGroupDescription =
new
ResourceGroupDescription();
resourceGroupDescription.ResourceType =
"Games"
;
encarte.GroupDescriptions.Add(resourceGroupDescription);
result.Add(encarte);
encarte =
new
EncartesViewDefinition();
encarte.GroupFilter = GroupFilter;
encarte.Title =
"Football"
;
ResourceGroupDescription resourceGroupDescription2 =
new
ResourceGroupDescription();
resourceGroupDescription2.ResourceType =
"Games"
;
encarte.GroupDescriptions.Add(resourceGroupDescription2);
result.Add(encarte);
encarte =
new
EncartesViewDefinition();
encarte.Title =
"Golf"
;
encarte.GroupFilter = GroupFilter;
ResourceGroupDescription resourceGroupDescription3 =
new
ResourceGroupDescription();
resourceGroupDescription3.ResourceType =
"Games"
;
encarte.GroupDescriptions.Add(resourceGroupDescription3);
result.Add(encarte);
return
result;
}
#endregion
#region Resources
public
ResourceCollection GenerateResources()
{
ResourceCollection result =
new
ResourceCollection();
Resource encarte1 =
new
Resource(
"Tennis"
);
Resource encarte2 =
new
Resource(
"Football"
);
Resource encarte3 =
new
Resource(
"Golf"
);
result.Add(encarte1);
result.Add(encarte2);
result.Add(encarte3);
return
result;
}
#endregion
#region Categories
public
ObservableCollection<Category> GenerateCategories()
{
ObservableCollection<Category> result =
new
ObservableCollection<Category>();
Category category =
new
Category();
category.DisplayName =
"Envio da Lista"
;
category.CategoryName =
"EnvioLista"
;
category.CategoryBrush = GetBrushFromHexString(
"#FF417542"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Conferência"
;
category.CategoryName =
"Conferência"
;
category.CategoryBrush = GetBrushFromHexString(
"#FF0465B3"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Sessão de Fotos"
;
category.CategoryName =
"Sessão"
;
category.CategoryBrush = GetBrushFromHexString(
"#FF973FA8"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Diagramação/Tratamento Fotos"
;
category.CategoryName =
"Diagramação"
;
category.CategoryBrush = GetBrushFromHexString(
"#FFE69E07"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Conferência - Bureau"
;
category.CategoryName =
"ConferênciaBureau"
;
category.CategoryBrush = GetBrushFromHexString(
"#FFE74220"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Conferência - Comercial"
;
category.CategoryName =
"ConferênciaComercial"
;
category.CategoryBrush = GetBrushFromHexString(
"#FFBD0037"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Validação - Comercial"
;
category.CategoryName =
"ValidaçãoComercial"
;
category.CategoryBrush = GetBrushFromHexString(
"#1FEF08"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Fechamento de Arquivos"
;
category.CategoryName =
"FechamentoArquivos"
;
category.CategoryBrush = GetBrushFromHexString(
"#56D1EF"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Recebimento nas Lojas"
;
category.CategoryName =
"Recebimento"
;
category.CategoryBrush = GetBrushFromHexString(
"#E0F80C"
);
result.Add(category);
category =
new
Category();
category.DisplayName =
"Validade do Material"
;
category.CategoryName =
"Validade"
;
category.CategoryBrush = GetBrushFromHexString(
"#FC03DB"
);
result.Add(category);
return
result;
}
#endregion
#region Get Color From Hex
public
static
SolidColorBrush GetBrushFromHexString(
string
aarrggbb)
{
String xamlString =
"<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Background=\""
+ aarrggbb +
"\"/>"
;
Canvas c = (Canvas)System.Windows.Markup.XamlReader.Load(xamlString);
return
(SolidColorBrush)c.Background;
}
#endregion
#region Find Category
private
Category FindCategory(ObservableCollection<Category> all,
string
name)
{
Category selected =
new
Category();
foreach
(Category current
in
all)
{
if
(current.CategoryName.Equals(name))
{
selected = current;
break
;
}
}
return
selected;
}
#endregion
public
Func<
object
,
bool
> GroupFilter
{
get
{
return
this
.groupFilter;
}
private
set
{
this
.groupFilter = value;
this
.OnPropertyChanged(() =>
this
.GroupFilter);
}
}
private
void
UpdateGroupFilter()
{
this
.GroupFilter =
new
Func<
object
,
bool
>(
this
.GroupFilterFunc);
}
private
List<
string
> teste {
get
;
set
; }
private
bool
GroupFilterFunc(
object
groupName)
{
IResource resource = groupName
as
IResource;
//The doubt is here!! In this function.....(next line doesn´t work)
return
resource ==
null
?
true
: resource.ResourceName ==
""
;
}
private
bool
Filter(
string
resourceName)
{
bool
filter =
false
;
foreach
(Etapa etapa
in
this
.appointments) {
if
(etapa.Encarte == resourceName) filter=
true
;
}
return
filter;
}
}
EncartesViewDefinition:
public
class
EncartesViewDefinition : CustomViewDefinition
{
public
EncartesViewDefinition()
{
this
.StretchGroupHeaders =
true
;
this
.VisibleDays = 7;
this
.LargeChangeInterval = DateTimeInterval.FromDays(7);
this
.GroupHeaderDateStringFormat =
"{0:dd dddd}"
;
this
.Orientation = Orientation.Horizontal;
}
protected
override
string
FormatVisibleRangeText(System.IFormatProvider formatInfo, System.DateTime rangeStart, System.DateTime rangeEnd, System.DateTime currentDate)
{
string
format = rangeStart.Year == rangeEnd.Year ?
(rangeStart.Month == rangeEnd.Month ?
"{0:d } - {1:d MMMM yyyy}"
:
"{0:d MMMM} - {1:d MMMM yyyy}"
) :
"{0:d MMMM yyyy} - {1:d MMMM yyyy}"
;
return
string
.Format(formatInfo, format, rangeStart, rangeEnd);
}
protected
override
DateTime GetVisibleRangeStart(DateTime currentDate, CultureInfo culture, DayOfWeek? firstDayOfWeek)
{
if
(culture ==
null
)
{
culture = CultureInfo.InvariantCulture;
}
DayOfWeek dayOfWeek = firstDayOfWeek ?? culture.DateTimeFormat.FirstDayOfWeek;
return
CalendarHelper.GetFirstDayOfWeek(currentDate, dayOfWeek);
}
protected
override
DateTime GetVisibleRangeEnd(DateTime currentDate, CultureInfo culture, DayOfWeek? firstDayOfWeek)
{
if
(culture ==
null
)
{
culture = CultureInfo.InvariantCulture;
}
DayOfWeek dayOfWeek = firstDayOfWeek ?? culture.DateTimeFormat.FirstDayOfWeek;
if
(
this
.DayEndTime >
this
.DayStartTime)
{
return
CalendarHelper.GetFirstDayOfWeek(currentDate, dayOfWeek).AddDays(
this
.VisibleDays - 1).Add(
this
.DayEndTime);
}
return
CalendarHelper.GetFirstDayOfWeek(currentDate, dayOfWeek).AddDays(
this
.VisibleDays).Add(
this
.DayEndTime);
}
}
Etapa.cs:
public
class
Etapa : Appointment
{
private
string
encarte;
public
string
Encarte
{
get
{
return
this
.Storage<Etapa>().encarte;
}
set
{
var storage =
this
.Storage<Etapa>();
if
(storage.encarte != value)
{
storage.encarte = value;
this
.OnPropertyChanged(() =>
this
.encarte);
}
}
}
public
override
IAppointment Copy()
{
IAppointment appointment =
new
Etapa();
appointment.CopyFrom(
this
);
return
appointment;
}
public
override
void
CopyFrom(IAppointment other)
{
Etapa appointment = other
as
Etapa;
if
(appointment !=
null
)
{
base
.CopyFrom(other);
}
}
}
My doubt is in function : private bool GroupFilterFunc(object groupName)!!
How do i apply the filter!!
Thanks