Friday, December 26, 2014

Flipping an UI element

What happens when you flip an UI element?

The following button has been flipped horizontally.


        <Button Height="50" Width="100" VerticalAlignment="Bottom">
            <Button.RenderTransform>
                <ScaleTransform ScaleX="-1"></ScaleTransform>
            </Button.RenderTransform> Flipped Button
        </Button>



The button was flipped, but it was also moved. That's because the button was flipped from its top left corner. To flip the button in place, you want to apply the ScaleTransform to its center, not its corner. An easy way to apply the ScaleTransform to the buttons center is to set the button's RenderTransformOrigin property to 0.5, 0.5.
       <Button RenderTransformOrigin=".5, .5" Height="50" Width="100" VerticalAlignment="Bottom">
            <Button.RenderTransform>
                <ScaleTransform ScaleX="-1"></ScaleTransform>
            </Button.RenderTransform> Flipped Button
        </Button>

To flip the button vertically, set the ScaleTransform object's ScaleY property.

        <Button RenderTransformOrigin=".5, .5" Height="50" Width="100" VerticalAlignment="Bottom">
            <Button.RenderTransform>
                <ScaleTransform ScaleY="-1"></ScaleTransform>
            </Button.RenderTransform> Flipped Button
        </Button>


Monday, December 15, 2014

Modified form submission app in ExtJs 5.0, MVC Web Api, Entity Framework 6 in ASP.NET

I have modified Simple application using ExtJs 5.0 (one of my previous post) using Entity framework 6, MVC Web Api, Ext Js 5.0, VS 2013. (With create, read functions in database). 

I can share the tutorial with you if requested.


Saturday, December 6, 2014

Behavior of TileMode property with its values in ImageBrush object

1) TileMode ="FlipX"

       <Grid.Background>
            <ImageBrush TileMode="FlipX" Viewport="0,0,.5,.5"
                ImageSource="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg">
            </ImageBrush>
        </Grid.Background>


2)  TileMode ="FlipY"

      <Grid.Background>
            <ImageBrush TileMode="FlipY" Viewport="0,0,.5,.5"
                ImageSource="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg">
            </ImageBrush>
        </Grid.Background>


3) TileMode ="FlipXY"

    <Grid.Background>
            <ImageBrush TileMode="FlipXY" Viewport="0,0,.5,.5"
                ImageSource="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg">
            </ImageBrush>
        </Grid.Background>



ImageBrush object

The ImageBrush object is used to paint objects by using an image as the source for the brush.

Example:

<Window x:Class="Brushes.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
         <Grid.Background>
            <ImageBrush
             ImageSource="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg">
            </ImageBrush>
        </Grid.Background>
    </Grid>
</Window>




We can select a portion of the source image to be used for painting by setting the ViewBox property.The following example shows cropping the upper left quarter of an image and using it for the ImageBrush object.

<Window x:Class="Brushes.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
<Grid.Background>
<ImageBrush Viewbox="0,0,.5,.5"
  ImageSource="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg">
</ImageBrush>
</Grid.Background>
    </Grid>
</Window>



Sunday, October 19, 2014

Using animation with triggers

We should remember that in WPF refers to an automated property change over a set period of time. You can animate an element’s size, location, color, or virtually any other property associated with an element.

You can use the Animation classes to implement these changes. So we use "Animation" objects for this purpose.The "Storyboard" object contains Animation objects and determines which element and property the Animation objects affect. As the answer to the question of "How do you start and stop an animation", is discussed here with an example.

We use "Trigger" object for this. All "Animation" objects must be housed within a "Trigger" object.
Following example:

1. BeginStoryboard is an action; it indicates that the contained storyboard should be started.

2. The EventTrigger class defines a collection of actions that should be initiated when the trigger is activated, and in this example, BeginStoryboard is the action that is initiated.

3. Thus, when the button indicated in this trigger is clicked, the described animation runs.

See the animation:

http://screencast.com/t/cuuXiQdRU

<Window x:Class="App1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
 
    <Grid>
        <Button Height="30" Width="200" HorizontalAlignment="Left">
            Animated Button
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Duration="0:0:5" Storyboard.TargetProperty="Height" To="200" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Button.Triggers>
        </Button>
    </Grid>
</Window>

Saturday, September 20, 2014

Grid creation in ExtJs

Again this is a learning purpose application and this is not the best approach. But for a beginner this will be fine. :)

My task is to build a grid from data returned by a ASP.NET MVC4/5 action method. Action method should return data encoded in JSON format similar to below.

{
   "success":true,
   "data":[
      {
         "Id":1,
         "Name":"Fixed",
         "Value":0,
         "ShortName":"Fix",
         "Description":"Issue is fixed and completed",
         "Color":"A4C400",
         "DomainId":0
      },
      {
         "Id":2,
         "Name":"Can not reproduce",
         "Value":0,
         "ShortName":"CantReprod",
         "Description":"Reported issue can not be repoduced",
         "Color":"60A917",
         "DomainId":0
      },
      {
         "Id":3,
         "Name":"Incomplete Data",
         "Value":0,
         "ShortName":"Incomplete",
         "Description":"Issue description is not enought",
         "Color":"FA6800",
         "DomainId":0
      },
      {
         "Id":4,
         "Name":"Expected Behaviour",
         "Value":0,
         "ShortName":"ExpctdBhvr",
         "Description":"This is expected behaviour under the normal circumstances",
         "Color":"6D8764",
         "DomainId":0
      }
   ]
}

My out put looks like below.

In my previous post related to ExtJs http://nalanijayasundara.blogspot.com/2014/09/simple-application-using-extjs-50.html I have described to set up the environment to run this kind of application in VS2012. So please have a look upto 3rd point.And then follow from here.

4. 4.1 . I have created my model as Color.js 
Ext.define('Assingment.model.Color', {
    extend'Ext.data.Model',
    fields: [
        { name'Id'type'int' },
        { name'Value'type'int' },
        { name'DomainId'type'int' },
        { name'Colour'type'string' },
        { name'Name'type'string' },
        { name'ShortName'type'string' },
        { name'Description'type'string' }
    ],
 
    schema: {
        namespace'Assingment.model',
        urlPrefix'/Home/GetColorInformation',
        proxy: {
            type'ajax',
            url'/Home/GetColorInformation',
            reader: {
                type'json',
                rootProperty'data'
            },
            extraParams: {
                name' '
            }
        }
    }
});

4.2 view/main/Main.js is like this.
Ext.define('Assingment.view.main.Main', {
    extend'Ext.form.Panel',
    requires: ['Assingment.model.Color'],
    xtype'app-main',
    referenceHoldertrue,
    controller'main',
    viewModel: {
        type'main'
    },

    layout: {
        type'vbox',
        align'stretch'
    },

    items: [
    {
        xtype'form',
        bind'{main}',
        items: [
            {
                xtype'grid',
                bind'{grid}',
                reference'fooPanel',
                columns: [
                    {
                        text"Colour",
                        width: 120,
                        dataIndex'Colour',
                        rendererfunction(value, metaData, record, rowIndex, colIndex, store) {
                            metaData.style = 'background-color: #' + record.data.Colour;
                        }
                    },
                    { text"Name"width: 380, dataIndex'Name' },
                    { text"Short Name"width: 380, dataIndex'ShortName' },
                    { text"Description"width: 380, dataIndex'Description' }
                ],
                buttons: [
                    {
                        text'UpdateGrid',
                        handler'onClickButton',
                    }
                ],
            }
        ]
    }]
});
4.3. view/main/MainCOntroller.js is like this.
Ext.define('Assingment.view.main.MainController', {
    extend'Ext.app.ViewController',

    requires: [
        'Ext.MessageBox'
    ],

    alias'controller.main',

    onClickButtonfunction () {
 
        var grid = this.lookupReference('fooPanel');
        var store = grid.getStore();
        store.load();
    },

    onConfirmfunction (choice) {
        if (choice === 'yes') {
            //
        }
    }
});
4.4.view/main/MainModel.js where 'Color' is located in root Models/Color.cs
Ext.define('Assingment.view.main.MainModel', {
    extend'Ext.app.ViewModel',
    requires: ['Assingment.model.Color'],
    alias'viewmodel.main',

    data: {
        name'Assingment'
    },
    stores: {
        grid: {
            model'Color'
        }
    }
    
});

4.5 Color.cs contains follows.
namespace Assignment2.Models
{
  public class Color
  {
    public string Colour { getset; }
    public string Name { getset; }
    public string ShortName { getset; }
    public string Description { getset; }
    public int Id { getset; }
    public int Value { getset; }
    public int DomainId { getset; }
 
    public Color() { }
 
    public Color(int id, string Name, int Value, string ShortName)
    {
      this.Id = id;
      this.Name = Name;
      this.Value = Value;
      this.ShortName = ShortName;
    }
  }
}
4.6. Root Controllers/HomeControllers.cs contains the action method like this.
using System.Collections.Generic;
using System.Web.Mvc;
 
using Assignment2.Models;
 
using Newtonsoft.Json;
 
namespace Assignment2.Controllers
{
  public class HomeController : Controller
  {
    public ActionResult Index()
    {
      return View();
    }
 
    [HttpGet]
    [AllowAnonymous]
    public ActionResult GetColorInformation()
    {
 
      return this.JsonResponse(
        new
        {
          success = true,
          data = new List<Color>
          {
            new Color
            {
              Id = 1,
              Name = "Fixed",
              Value = 0,
              ShortName = "Fix",
              Description = "Issue is fixed and completed",
              Colour = "A4C400",
              DomainId = 0
 
            },
            new Color()
            {
              Id = 2,
              Name = "Can not reproduce",
              Value = 0,
              ShortName = "CantReprod",
              Description = "Reported issue can not be repoduced",
              Colour = "60A917",
              DomainId = 0
            },
            new Color()
            {
              Id = 3,
              Name = "Incomplete Data",
              Value = 0,
              ShortName = "Incomplete",
              Description = "Issue description is not enought",
              Colour = "FA6800",
              DomainId = 0
            },
             new Color()
            {
              Id = 4,
              Name = "Expected Behaviour",
              Value = 0,
              ShortName = "ExpctdBhvr",
              Description = "This is expected behaviour under the normal circumstances",
              Colour = "6D8764",
              DomainId = 0
            },
          }
        });
    }
 
    protected ContentResult JsonResponse(object response)
    {
      return new ContentResult { Content = JsonConvert.SerializeObject(response), ContentType = "application/json"ContentEncoding = System.Text.Encoding.UTF8 };
    }
  }
}
Following is my folder structure in VS.
That's it. Now you can run in VS and see the grid content when pressing the button "UpdateGrid" in the browser.

Friday, September 19, 2014

Something I always forget

I just wanted to note it down :)

Access modifiers in C#

public : Access is not restricted.

protected : Access is limited to the containing class or types derived from the containing class.

Internal : Access is limited to the current assembly.
protected internal: Access is limited to the current assembly or types derived from the containing class.


private : Access is limited to the containing type.