Group filtering doesnt work

6 posts, 1 answers
  1. Pavel
    Pavel avatar
    21 posts
    Member since:
    Sep 2010

    Posted 01 Feb 2011 Link to this post

    I tried to work with Demo Example: Grupping - Advanced, but it doesn´t work to me.I did small changes in code, but nothing difficult. The only thing which is working is Enable/disable groupping. When I uncheck a layer, layer is still visible in ScheduleView. Am I doing something wrong in my code?

    MainWindow.xaml

    <Window x:Class="TestScheduleView.MainWindow"
            Title="MainWindow" Height="500" Width="800"
            xmlns:telerikScheduler="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.ScheduleView"
            xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls">
        <Window.Resources>
            <SolidColorBrush x:Key="MainBackground" Color="#FF000000" />
            <LinearGradientBrush x:Key="SubHeadingBackground" EndPoint="0.5,1" MappingMode="RelativeToBoundingBox"
                    StartPoint="0.5,0">
                <GradientStop Color="#FF4B4B4B" Offset="1" />
                <GradientStop Color="#FF6E6E6E" />
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="SelectionOptionBackground" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF1E1E1E" Offset="0" />
                <GradientStop Color="#FF040404" Offset="1" />
            </LinearGradientBrush>
            <SolidColorBrush x:Key="SelectionOptionBorderBrush" Color="#FF313132" />
            <Style x:Key="SelectionOptionStyle" TargetType="Border">
                <Setter Property="Background" Value="{StaticResource SelectionOptionBackground}" />
                <Setter Property="BorderBrush" Value="{StaticResource SelectionOptionBorderBrush}" />
                <Setter Property="BorderThickness" Value="1 0 1 1" />
                <Setter Property="MinHeight" Value="70" />
            </Style>
        </Window.Resources>
      
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="32" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="225" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Border Grid.RowSpan="2" Grid.ColumnSpan="2" telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True" />
      
            <Border Background="#FF212121" Grid.RowSpan="2" />
      
            <Border Background="{StaticResource MainBackground}" Grid.ColumnSpan="2">
                <TextBlock Text="Grouping and Filtering"  FontFamily="Segoe UI"
                        HorizontalAlignment="Left" Foreground="#FFE5E2E2" Margin="13 0 0 0" FontSize="16" TextWrapping="Wrap"
                        VerticalAlignment="Center" />
            </Border>
      
            <StackPanel Grid.Row="1" Orientation="Vertical">
                <Border Background="{StaticResource SubHeadingBackground}" Height="32">
                    <TextBlock Text="Select a Layer" TextWrapping="Wrap" FontSize="13" Foreground="#FFEBE9E9"
                            FontFamily="Segoe UI" VerticalAlignment="Center" Margin="13 0 0 0" />
                </Border>
                <Border Background="{StaticResource MainBackground}" Height="32">
                    <CheckBox IsChecked="{Binding EnableGrouping}" Content="Enable Grouping"
                             Foreground="#FFA9A9A9" FontWeight="Normal"
                            Margin="13 0 0 0" VerticalAlignment="Center" />
                </Border>
      
                <Border Style="{StaticResource SelectionOptionStyle}" Height="32">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <CheckBox IsChecked="{Binding ShowPresentationLayer}" Content="Fixed" IsEnabled="{Binding EnableGrouping}"
                                  Foreground="#FFA9A9A9" VerticalAlignment="Center" Margin="10" Padding="10 0 0 0" />
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource SelectionOptionStyle}">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <CheckBox IsChecked="{Binding ShowDataLayer}" Content="PeriodicFixed" IsEnabled="{Binding EnableGrouping}"
                                  Foreground="#FFA9A9A9"  VerticalAlignment="Center" Margin="10" Padding="10 0 0 0"/>
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource SelectionOptionStyle}">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <CheckBox IsChecked="{Binding ShowBusinessLayer}" Content="Periodical" IsEnabled="{Binding EnableGrouping}"
                                  Foreground="#FFA9A9A9"  VerticalAlignment="Center" Margin="10" Padding="10 0 0 0"/>
                    </StackPanel>
                </Border>
            </StackPanel>
      
            <telerikScheduler:RadScheduleView Grid.Column="1" Grid.Row="1" 
                                              SnapAppointments="True" 
                                              x:Name="radScheduler"
                    AppointmentsSource="{Binding Appointments}" 
                    GroupDescriptionsSource="{Binding GroupDescriptions}"
                    ActiveViewDefinitionIndex="1">
      
                <telerikScheduler:RadScheduleView.ViewDefinitions>
                    <telerikScheduler:DayViewDefinition GroupFilter="{Binding GroupFilter}" Orientation="Horizontal" DayStartTime="12:00:00" />
                    <telerikScheduler:WeekViewDefinition GroupFilter="{Binding GroupFilter}" Orientation="Horizontal" DayStartTime="12:00:00" />
                    <telerikScheduler:MonthViewDefinition GroupFilter="{Binding GroupFilter}" />
                    <telerikScheduler:TimelineViewDefinition GroupFilter="{Binding GroupFilter}" />
                </telerikScheduler:RadScheduleView.ViewDefinitions>
      
      
                <telerikScheduler:RadScheduleView.ResourceTypesSource>
                    <telerikScheduler:ResourceTypeCollection>
                        <telerikScheduler:ResourceType Name="Category">
                            <telerikScheduler:Resource ResourceName="Fixed" />
                            <telerikScheduler:Resource ResourceName="PeriodicFixed" />
                            <telerikScheduler:Resource ResourceName="Periodical" />
                        </telerikScheduler:ResourceType>
                    </telerikScheduler:ResourceTypeCollection>
                </telerikScheduler:RadScheduleView.ResourceTypesSource>
            </telerikScheduler:RadScheduleView>
        </Grid>
    </Window>

    MainWindow.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
      
    namespace TestScheduleView
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
      
                this.DataContext = new ViewModel();
            }
        }
    }

    ViewModel.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Windows.Controls.ScheduleView;
    using Telerik.Windows.Controls;
    using System.ComponentModel;
      
    namespace TestScheduleView
    {
        class ViewModel : ViewModelBase
        {
            private bool showBusinessLayer = true;
            private bool showDataLayer = true;
            private bool showPresentationLayer = true;
            private bool enableGrouping = true;
            private GroupDescriptionCollection groupDescriptions;
            private Func<object, bool> groupFilter;
      
            public bool ShowBusinessLayer
            {
                get
                {
                    return this.showBusinessLayer;
                }
                set
                {
                    if (this.showBusinessLayer != value)
                    {
                        this.showBusinessLayer = value;
                        this.OnPropertyChanged(() => this.ShowBusinessLayer);
                        this.UpdateGroupFilter();
                    }
                }
            }
      
            public bool ShowDataLayer
            {
                get
                {
                    return this.showDataLayer;
                }
                set
                {
                    if (this.showDataLayer != value)
                    {
                        this.showDataLayer = value;
                        this.OnPropertyChanged(() => this.ShowDataLayer);
                        this.UpdateGroupFilter();
                    }
                }
            }
      
            public bool ShowPresentationLayer
            {
                get
                {
                    return this.showPresentationLayer;
                }
                set
                {
                    if (this.showPresentationLayer != value)
                    {
                        this.showPresentationLayer = value;
                        this.OnPropertyChanged(() => this.ShowPresentationLayer);
                        this.UpdateGroupFilter();
                    }
                }
            }
      
            public bool EnableGrouping
            {
                get
                {
                    return this.enableGrouping;
                }
                set
                {
                    if (this.enableGrouping != value)
                    {
                        this.enableGrouping = value;
                        this.OnPropertyChanged(() => this.EnableGrouping);
      
                        this.UpdateGroupDescriptions();
                    }
                }
            }
      
            public GroupDescriptionCollection GroupDescriptions
            {
                get
                {
                    if (this.groupDescriptions == null)
                    {
                        this.groupDescriptions = new GroupDescriptionCollection() { new DateGroupDescription() };
                        this.UpdateGroupDescriptions();
                    }
                    return this.groupDescriptions;
                }
            }
      
            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 bool GroupFilterFunc(object groupName)
            {
                IResource resource = groupName as IResource;
      
                if (resource == null)
                    return true;
      
                IEnumerable<string> enumerable = GetEnabledGroups();
      
                foreach (string str in enumerable)
                {
                    if (str.ToLower().Equals(resource.ResourceName.ToLower()))
                        return true;
                }
      
                return false;
            }
      
            private ObservableAppointmentCollection appointments;
            public ObservableAppointmentCollection Appointments
            {
                get
                {
                    return this.appointments;
                }
                set
                {
                    this.appointments = value;
                }
            }
      
            public ViewModel()
            {
                appointments = new ObservableAppointmentCollection();
      
                Appointment appointment = new Appointment();
                appointment.Start = DateTime.Now;
                appointment.End = DateTime.Now.AddHours(1);
                appointment.Subject = "New appointment";
                Resource r = new Resource();
                r.ResourceName = "Periodical";
                r.ResourceType = "Category"; 
                appointment.Resources.Add(r);
                Appointments.Add(appointment); 
            }
      
            private IEnumerable<string> GetEnabledGroups()
            {
                List<string> enabledGroups = new List<string>();
      
                if (this.ShowPresentationLayer) enabledGroups.Add("Fixed");
                if (this.ShowDataLayer) enabledGroups.Add("PeriodicFixed");
                if (this.ShowBusinessLayer) enabledGroups.Add("Periodical");
      
                return enabledGroups;
            }
      
            private void UpdateGroupDescriptions()
            {
                if (this.EnableGrouping)
                {
                    ResourceGroupDescription groupDescription = new ResourceGroupDescription();
                    groupDescription.ResourceType = "Category";
                    this.GroupDescriptions.Add(groupDescription);
                }
                else
                {
                    this.GroupDescriptions.RemoveAll((GroupDescription g) => g is ResourceGroupDescription);
                }
            }
        }
    }

  2. Answer
    Dani
    Admin
    Dani avatar
    848 posts

    Posted 03 Feb 2011 Link to this post

    Hello Pavel,

    The Grouping Advanced example uses the ViewModel as a local resource and sets the DataContext explicitly on the LayoutRoot Grid. I suggest you use the same approach.

    A working example is attached for your convenience.

    Kind regards,
    Dani
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Atanas
    Admin
    Atanas avatar
    22 posts

    Posted 25 Feb 2011 Link to this post

    Hello Pavel,

     I'm changing the title of the forum from "Group filtering doesn´t work" to "Group filtering doesn't work". because of the Czech encoding that you used when you typed this symbol " ' ".

    Could you please try one more time to mark it as answer?

    Regards,
    Atanas
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. Atanas
    Admin
    Atanas avatar
    22 posts

    Posted 03 Mar 2011 Link to this post

    Hello Pavel,

    We finally renamed the forum!

    The issue was really hard one and we had to make a fix in our ORM regarding this encoding issue.

    Now you should be able to close this forum!

    Best wishes,
    Atanas
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  6. Kshamesh
    Kshamesh avatar
    16 posts
    Member since:
    Aug 2012

    Posted 19 Oct 2012 Link to this post

    Hello Dani,

    I would like know why we there is again need to set the DataContext explicitly on the LayoutRoot Grid, since the datacontext is already set in the view.cs constructor.

    Thanks,
    Kshamesh
  7. Paolo
    Paolo avatar
    1 posts
    Member since:
    Nov 2008

    Posted 04 Dec 2012 Link to this post

    To Solve this problem make this:
    Create a class:

    public class BindingProxy : Freezable

    {

    #region

     

     

    Overrides of Freezable

    protected override Freezable CreateInstanceCore()

    {

    return new BindingProxy();

    }

    #endregion

    public object Data

    {

     

     

    get

    {

     

    return (object)GetValue(DataProperty);

    }

     

    set

    {

    SetValue(DataProperty,

     

    value);

    }

    }

     

    // Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc...

     

    public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));

    }

    Create a resource of this class

    <UserControl.Resources>

     <local:BindingProxy x:Key="proxy" Data="{Binding}" />

     </UserControl.Resources>


    And After use in this mode:

     

     

     

    <telerik:RadScheduleView.ViewDefinitions>

                    <telerik:DayViewDefinition GroupFilter="{Binding Data.GroupFilter,Source={StaticResource proxy}}" />

                    <telerik:WeekViewDefinition GroupFilter="{Binding Data.GroupFilter,Source={StaticResource proxy}}"/>

                    <telerik:MonthViewDefinition GroupFilter="{Binding Data.GroupFilter,Source={StaticResource proxy}}"/>

                </telerik:RadScheduleView.ViewDefinitions>

    Hope this help you!! :D

     

     


     

Back to Top
UI for WPF is Visual Studio 2017 Ready