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;
using Telerik.Windows.Data;

namespace ProgrammaticFilter
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class Window1 : Window
	{
		public Window1()
		{
			InitializeComponent();

            var senderFilter = (StringContainsFilterDescription) this.Resources["SenderFilter"];
            var subjectFilter = (StringContainsFilterDescription) this.Resources["SubjectFilter"];
            var composite = new CompositeFilterDescription();
            composite.FilterDescriptions.Add(senderFilter);
            composite.FilterDescriptions.Add(subjectFilter);
            RadGridView1.FilterDescription = composite;

			RadGridView1.ItemsSource = new Message[] { 
				new Message { Sender = "tom@hanna-barbera.com", Subject = "Cats are cool", Size = 100 },
				new Message { Sender = "jerry@hanna-barbera.com", Subject = "Mice are cool", Size = 100 },
				new Message { Sender = "spike@hanna-barbera.com", Subject = "Dogs are cool", Size = 100 }
			};


		}

		private void filterButton_Click(object sender, RoutedEventArgs e)
		{
			//var masterFilter = (CompositeFilterDescription) (this.RadGridView1.FilterDescription);
			
			//var subjectFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[0];
			//subjectFilter.Values.Add("Cats are cool");
			//subjectFilter.Values.Add("Mice are cool");

			//var senderFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[1];
			//senderFilter.Values.Add("jerry@hanna-barbera.com");


			var masterFilter = (CompositeFilterDescription) (this.RadGridView1.FilterDescription);
			var subjectFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[0];
			subjectFilter.Values.Add("Cats are cool");
			var senderFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[1];
			senderFilter.Values.Add("jerry@hanna-barbera.com");
		}


	}
}
