예제 #1
0
 private void RaiseContentChanged(EventArgs args)
 {
     if (_ContentChanged != null)
     {
         _ContentChanged.Raise(args);
     }
 }
예제 #2
0
 private void RaisePropertyValueChanged(EventArgs args)
 {
     if (_PropertyValueChanged != null)
     {
         _PropertyValueChanged.Raise(args);
     }
 }
예제 #3
0
파일: WeakEvents.cs 프로젝트: ganouver/gdk
 public void Tick()
 {
     if (_event != null)
     {
         _event.Raise();
     }
 }
예제 #4
0
        /// <summary>
        /// при генерации любого триггера генерируем событие
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnTrigger(object sender, EventArgs args)
        {
            if (Changed != null)
            {
                Changed(this, EventArgs.Empty);
            }

            if (_changed != null)
            {
                _changed.Raise(args);
            }
        }
예제 #5
0
            public void Raise(string PropertyName)
            {
                WeakEvent evt;

                if (!string.IsNullOrEmpty(PropertyName) &&
                    _propertyEvents.TryGetValue(PropertyName, out evt))
                {
                    evt.Raise();
                }

                if (_anyChange != null)
                {
                    _anyChange.Raise(new PropertyChangedEventArgs(PropertyName));
                }
            }
예제 #6
0
        public void test_FilterCollection()
        {
            WeakObservableCollection<FilterItem> items = new WeakObservableCollection<FilterItem>() {
                new FilterItem() {Property = false}};

            var manualTrigger = new WeakEvent(items);

            var filtered = items.ToAutoProcessed().FilteredBy(x => x.Property)
                .UpdateOn(x => x.PropertyTrigger)
                .UpdateOn(x => null);

            var filteredM = items.ToAutoProcessed().FilteredBy(x => x.Property).UpdateOn(manualTrigger);

            Assert.AreEqual(0, filtered.Count);
            items[0].Property = true;
            Assert.AreEqual(1, filtered.Count);

            Assert.AreEqual(0, filteredM.Count);
            manualTrigger.Raise();
            Assert.AreEqual(filtered.Count, filteredM.Count);

            items[0].Property = false;
            Assert.AreEqual(0, filtered.Count);

            items.Add(new FilterItem() { Property = true });
            Assert.AreEqual(1, filtered.Count);

            items.Add(new FilterItem() { Property = false });
            Assert.AreEqual(1, filtered.Count);

            items.Add(new FilterItem() { Property = true });
            Assert.AreEqual(2, filtered.Count);
            items.Remove(items.First(x => x.Property));
            Assert.AreEqual(1, filtered.Count);
            Assert.AreSame(items.Single(x => x.Property), filtered[0]);
            items.Remove(items.First(x => !x.Property));
            Assert.AreEqual(1, filtered.Count);

            items.Clear();
            Assert.AreEqual(0, filtered.Count);

            //тестируем работу сортировки
            var rawColl = new WeakObservableCollection<string>();

            //сортируем по первым символам
            var sorted = rawColl.ToAutoProcessed().SortedOn((x, y) => x.Substring(0, 1).CompareTo(y.Substring(0, 1)));
            rawColl.Add("5ф");
            rawColl.Add("2ф");
            rawColl.Add("4ф");
            rawColl.Add("3ф");
            rawColl.Add("1с");
            rawColl.Add("5с");
            rawColl.Add("2с");
            rawColl.Add("4с");
            rawColl.Add("3с");
            rawColl.Add("1с");

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual((i + 1).ToString(), sorted[2 * i].Substring(0, 1));
                Assert.AreEqual((i + 1).ToString(), sorted[2 * i + 1].Substring(0, 1));
            }
        }
예제 #7
0
 private CompoundWeakEvent()
 {
     _evt    = new WeakEvent(this);
     trigger = new EventReceiver((x, y) => _evt.Raise(y));
 }