using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;

namespace LightSwitchApplication
{
    public partial class Schulungsdetails
    {
        partial void Schulung_Loaded(bool succeeded)
        {
            // Write your code here.
            this.SetDisplayNameFromEntity(this.Schulung);
        }

        partial void Schulung_Changed()
        {
            // Write your code here.
            this.SetDisplayNameFromEntity(this.Schulung);
        }

        partial void Schulungsdetails_Saved()
        {
            // Write your code here.
            this.SetDisplayNameFromEntity(this.Schulung);
        }

        partial void Schulungsdetails_Saving(ref bool handled)
        {
         // Write your code here.

        }

        partial void Schulungsdetails_Created()
        {
         // 1. Steuerelement suchen (einmalig)
         this.FindControl("Schulungsthema").ControlAvailable += new EventHandler<ControlAvailableEventArgs>(ControlAvailable);
        }

        void ControlAvailable(object sender, ControlAvailableEventArgs e)
        {
         // 2. Eventhandler binden (einmalig)
         System.Windows.Controls.TextBox control = (System.Windows.Controls.TextBox)e.Control;
         control.Foreground = new System.Windows.Media.SolidColorBrush(Colors.White);
         control.FontWeight = FontWeights.Bold;
         control.TextChanged += new System.Windows.Controls.TextChangedEventHandler(control_TextChanged);

        }

        void control_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
         // 3. Reagieren auf jede Änderung
         System.Windows.Controls.TextBox control = sender as TextBox;
         if (String.IsNullOrEmpty(control.Text) || control.Text.Length < 10)
         {
          control.Background = new System.Windows.Media.SolidColorBrush(Colors.Orange);
         }
         else if (!String.IsNullOrEmpty(control.Text) && control.Text.Length < 20)
         {
          control.Background = new System.Windows.Media.SolidColorBrush(Colors.Yellow);
         }
         else
         {
          control.Background = new System.Windows.Media.SolidColorBrush(Colors.White);
         } 
        }
    }
}