TextBoxExtended.cs :  » Game » Balder » System » Windows » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » Balder 
Balder » System » Windows » Controls » TextBoxExtended.cs
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Browser;

namespace System.Windows.Controls{
  public class TextBoxExtended : TextBox
  {
    //Template internal content scroll viewer
    ScrollViewer  _content = null;
    //Content border
    Border        _content_border = null;
    //Text calculations
    TextBlock     _size_block = null;

    /// <summary>An Event beeing fired when template content found and initialized</summary>
    public event RoutedEventHandler ContentFound;

    public TextBoxExtended()
    {
      //Since we do not use any own style for this control set DefaultStyleKey to TextBox
      DefaultStyleKey = typeof(TextBoxExtended);
    }

    //In this part we have Get a Template Child 'ContentElement'.
    //This is ScrollViewer of TexBox
    public override void OnApplyTemplate()
    {
      base.OnApplyTemplate();
      _content = base.GetTemplateChild("ContentElement") as ScrollViewer;
      if (_content == null)
        return;
      _content.LayoutUpdated += new EventHandler(OnContent_LayoutUpdated);
    }

    //Getting child content of scrollviewer
    private void OnContent_LayoutUpdated(object sender, EventArgs e)
    {
      if (_content_border != null)
        return;
      _content_border = VisualTreeHelper.GetChild(_content, 0) as Border;
      if (_content_border != null)
      {
        int count = VisualTreeHelper.GetChildrenCount(_content_border);
        if (count > 0)
        {
          Grid grid = VisualTreeHelper.GetChild(_content_border, 0) as Grid;
          if (grid != null)
          {
            //OK NOW TRY TO CREATE A LITTLE TextBlock for text mesurament calculations
            _size_block = new TextBlock()
            {
             Foreground = null,
             VerticalAlignment = VerticalAlignment.Top,
             HorizontalAlignment = HorizontalAlignment.Left,
             FontFamily  = FontFamily,
             FontSize    = FontSize,
             FontStretch = FontStretch,
             FontStyle   = FontStyle,
             FontWeight  = FontWeight
            };
            grid.Children.Add(_size_block);

            IEnumerable<System.Windows.Controls.Primitives.ScrollBar> found = (from child in grid.Children.ToList() where child is System.Windows.Controls.Primitives.ScrollBar select child as System.Windows.Controls.Primitives.ScrollBar);
            if (found.Count() > 0)
            {
              VerticalScrollBar = (from sc in found where sc.Name == "VerticalScrollBar" select sc).First();
              HorizontalScrollBar = (from sc in found where sc.Name == "HorizontalScrollBar" select sc).First();
              if (ContentFound != null)
                ContentFound(this, new RoutedEventArgs());
            }
            //_content.Clip = new RectangleGeometry() { Rect = new Rect(0, 0, ActualWidth, ActualHeight) };
          }
        }
      }
    }

    public Size MesureText(string Text)
    {
      if (_size_block != null)
      {
        _size_block.Text = string.IsNullOrEmpty(Text.Replace("\r","").Replace("\n","")) ? " ":Text;
        return new Size(_size_block.ActualWidth, _size_block.ActualHeight);
      }
      return Size.Empty;
    }

    public bool CanDoTextMesure
    {
      get { return _size_block != null; }
    }

    public System.Windows.Controls.Primitives.ScrollBar VerticalScrollBar
    {
      get;
      set;
    }

    public System.Windows.Controls.Primitives.ScrollBar HorizontalScrollBar
    {
      get;
      set;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.