hdolder.com srl

  hdc Home | Contenido  | KO1  | Director | Direcciones | email
  BLOCKS - Ejemplo BO1

v100

 

 

 *** Documento en elaboración ***

La siguiente figura ilustra una mini-aplicación WPF que utiliza varios Controles estándar (visuales) y un BLOCK genérico de la Plataforma BLOCKS. 

El BLOCK genérico en este ejemplo permite que la aplicación se resuelva en forma completamente declarativa usando XAML sin necesidad de incorporar "code-behind".

El BLOCK genérico utilizado es el denominado BSolidColorBrush que tiene tres Input Properties (InRed, InGreen e InBlue) y una Output Property (SCBrush). Mas abajo se incluye el código XAML y las partes relevantes el código del BLOCK BSolidColorBrush.

El código XAML es:

<Window 
	x:Class="BSolidColorBrush.Window1"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:blocks='clr-namespace:ob.gc;assembly=BLOCKS_WPF'
	Title="BSolidColorBrush Demo - Color Chooser" 
	Width="410" 
	Height="250"
	>

	<Canvas x:Name="obSL" Background="DarkGreen" >

	<!-- Nombre usado en obGC.js -->
	<Canvas x:Name="obWFCanvas" Width="400" Height="190"
		Background="#000044" Canvas.Left="0" Canvas.Top="20" >
	<Slider 
		Name="RedScroll"
		Orientation="Vertical" 
		Height="128" 
		Width="45" 
		Minimum="0"
		Maximum="255" 
		Value="128"
		TickPlacement="BottomRight" 
		TickFrequency="16"
		Canvas.Left="10" 
		Canvas.Top="30" 
		/>
	<Slider 
		Name="GreenScroll"
		Orientation="Vertical" 
		Height="128" 
		Width="45" 
		Minimum="0"
		Maximum="255" 
		Value="128"
		TickPlacement="BottomRight" 
		TickFrequency="16"
		Canvas.Left="50" 
		Canvas.Top="30" 
		/>
	<Slider 
		Name="BlueScroll"
		Orientation="Vertical" 
		Height="128" 
		Width="45" 
		Minimum="0"
		Maximum="255" 
		Value="128"
		TickPlacement="BottomRight" 
		TickFrequency="16"
		Canvas.Left="100" 
		Canvas.Top="30" 
		/>
	<Label Background="Black" Foreground="Orange" FontSize="10" 
		Canvas.Left="10" Canvas.Top="5" Width="40" 
		Height="20" Content="Red"/>
	<Label Background="Black" Foreground="LightGreen" FontSize="10" 
		Canvas.Left="55" Canvas.Top="5" Width="40" 
		Height="20" Content="Green"/>
	<Label Background="Black" Foreground="LightBlue" FontSize="10" 
		Canvas.Left="100" Canvas.Top="5" Width="40" 
		Height="20" Content="Blue"/>

	<Label Background="Black" Foreground="Orange" FontSize="10" 
		Canvas.Left="10" Canvas.Top="160" Width="40" 
		Height="20" Name="RedValue"
		Content="{Binding ElementName=RedScroll,Path=Value}"
		/>
	<Label Background="Black" Foreground="LightGreen" FontSize="10" 
		Canvas.Left="55" Canvas.Top="160" Width="40" 
		Height="20" Name="GreenValue"
		Content="{Binding ElementName=GreenScroll,Path=Value}"
		/>
	<Label Background="Black" Foreground="LightBlue" FontSize="10" 
		Canvas.Left="100" Canvas.Top="160" Width="40" 
		Height="20" Name="BlueValue"
		Content="{Binding ElementName=BlueScroll,Path=Value}"
		/>

	<!-- BSolidColorBrush -->
	<blocks:BSolidColorBrush
		Name="BSCB1"
		InRed="{Binding ElementName=RedScroll,Path=Value}"
		InGreen="{Binding ElementName=GreenScroll,Path=Value}"
		InBlue="{Binding ElementName=BlueScroll,Path=Value}"
		/>

	<Rectangle 
		Name="ColorPanel"
		Fill="{Binding ElementName=BSCB1,Path=SCBrush}" 
		Canvas.Left="200" 
		Width="200" 
		Height="190" 
	/>
	</Canvas>
	</Canvas>
</Window>

y el codigo en C# del componente BSolidColorBrush es (IMORTANTE: casi la totalidad del codigo fué creado mediante  las Development Tools):

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  BSolidColorBrush BLOCKS Control
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using ....
using ob.core;

namespace ob.gc
{
    public class BSolidColorBrush : BLOCK
    {
        static int iii = 0;  // for debugging

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Connectors del BLOCK
        // (Dependency Properties)
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // [**
 
    public double InRed 
    { 
      get { return (double)GetValue(InRedProperty); } 
      set {  
            SetValue(InRedProperty, value);  
          } 
    } 
    public static readonly DependencyProperty InRedProperty = 
        DependencyProperty.Register("InRed", typeof(double), typeof(BSolidColorBrush), 
             new PropertyMetadata(0.0, new PropertyChangedCallback(OnInRedChanged))); 
 
    private static void OnInRedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
      ((BSolidColorBrush)d).OnInRedChanged(e); 
    } 
 
    protected virtual void OnInRedChanged(DependencyPropertyChangedEventArgs e) 
    { 
         SetSolidColorBrush();
    } 

    public double InGreen 
    { 
      get { return (double)GetValue(InGreenProperty); } 
      set {  
            SetValue(InGreenProperty, value);  
          } 
    } 
    public static readonly DependencyProperty InGreenProperty = 
        DependencyProperty.Register("InGreen", typeof(double), typeof(BSolidColorBrush), 
             new PropertyMetadata(0.0, new PropertyChangedCallback(OnInGreenChanged))); 
 
    private static void OnInGreenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
      ((BSolidColorBrush)d).OnInGreenChanged(e); 
    } 
 
    protected virtual void OnInGreenChanged(DependencyPropertyChangedEventArgs e) 
    { 
          SetSolidColorBrush();
    } 


    public double InBlue 
    { 
      get { return (double)GetValue(InBlueProperty); } 
      set {  
            SetValue(InBlueProperty, value);  
          } 
    } 
    public static readonly DependencyProperty InBlueProperty = 
        DependencyProperty.Register("InBlue", typeof(double), typeof(BSolidColorBrush), 
             new PropertyMetadata(0.0, new PropertyChangedCallback(OnInBlueChanged))); 
 
    private static void OnInBlueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
      ((BSolidColorBrush)d).OnInBlueChanged(e); 
    } 
 
    protected virtual void OnInBlueChanged(DependencyPropertyChangedEventArgs e) 
    { 
           SetSolidColorBrush();
    } 
 
    public SolidColorBrush SCBrush 
    { 
      get { return (SolidColorBrush)GetValue(SCBrushProperty); } 
      set {  
            SetValue(SCBrushProperty, value);  
          } 
    } 
    public static readonly DependencyProperty SCBrushProperty = 
        DependencyProperty.Register("SCBrush", typeof(SolidColorBrush), typeof(BSolidColorBrush), 
             new PropertyMetadata(Brushes.Gray, new PropertyChangedCallback(OnSCBrushChanged))); 
 
    private static void OnSCBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
      ((BSolidColorBrush)d).OnSCBrushChanged(e); 
    } 
 
    protected virtual void OnSCBrushChanged(DependencyPropertyChangedEventArgs e) 
    { 
      // ....... 
    } 
 
        // **]

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Constructor 
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        public  BSolidColorBrush():base()
        {
            iii = 0;
            // [**
            // **]
        }

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Logica del Block
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // [**
        private void SetSolidColorBrush()
        {
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();

            // Describes the brush's color using RGB values. 
            // Each value has a range of 0-255.
            mySolidColorBrush.Color = Color.FromArgb(255, Convert.ToByte(InRed), Convert.ToByte(InGreen), Convert.ToByte(InBlue));

            SCBrush = mySolidColorBrush;
        }

        // **]
    }
}
 

  TBW The BLOCKS World

©2011 hdolder.com srl