Click here to Skip to main content
15,893,401 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 3 - Southwind Load

Rate me:
Please Sign up or sign in to vote.
4.62/5 (7 votes)
21 Nov 2012CPOL23 min read 24.5K   319   10  
In this part we'll write the loading application to move data from Northwind to Southwind.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media.Animation;
using Signum.Utilities;
using System.Windows.Media;
using Signum.Entities;

namespace Signum.Windows
{
    public class DataBorder : Border
    {
        public static readonly DependencyProperty AutoChildProperty =
           DependencyProperty.Register("AutoChild", typeof(bool), typeof(DataBorder), new UIPropertyMetadata(false));
        public bool AutoChild
        {
            get { return (bool)GetValue(AutoChildProperty); }
            set { SetValue(AutoChildProperty, value); }
        }

        public DataBorder()
        {
            this.DataContextChanged += new DependencyPropertyChangedEventHandler(DataBorder_DataContextChanged);
            this.Loaded += new RoutedEventHandler(DataBorder_Loaded);
        }

        void DataBorder_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= DataBorder_Loaded;
            RecalculateVisibility(null, DataContext);
        }

        void DataBorder_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            RecalculateVisibility(e.OldValue, e.NewValue);
        }

        DoubleAnimation animation = new DoubleAnimation()
        {
            Duration = new Duration(TimeSpan.FromSeconds(0.1)),
            From = 0,
            To = 1,
        };

        private void RecalculateVisibility(object oldValue, object newValue)
        {
            if(AutoChild)
            {
                // when datacontext change is fired but its not loaded, it's quite possible that some Common.Routes are not working yet
                if (newValue == null || !IsLoaded) 
                    Child = null;
                else
                {
                    EntitySettings setting = Navigator.GetEntitySettings(newValue.GetType());
                    if (setting == null)
                        Child = new TextBox
                        {
                            Text = "No EntitySettings for {0}".Formato(newValue.GetType()),
                            Foreground = Brushes.Red,
                            FontWeight = FontWeights.Bold
                        };
                    else
                        Child = setting.CreateView((ModifiableEntity)newValue, Common.GetTypeContext(this)); 
                }
            }
            if (Child != null)
            {
                if (newValue == null)
                    Child.Visibility = Visibility.Hidden;
                else
                    Child.Visibility = Visibility.Visible;

                if (oldValue != null && newValue != null)
                    Child.BeginAnimation(UIElement.OpacityProperty, animation);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions