Lift the curtains!!!

So just the other day I was looking at one of the other blogs and it occurred to me that I could contribute in my own way!! and Lo and behold!!! heres my blog Up and running..

The next thing in question was the content and what better thing to write on than the work i am doing. So what you'll be seeing here is some code working with Avalon. Since there are lots of blogs documenting on Avalon features, I will just try to show how easy it it to build up apps. So the code snippets here are more like features of full blown apps.

The software I have on my computer is: WinFX runtime, SDK, VC# express, and Visual Studio extensions for WinFX. All these are available from the Microsoft site.

Now about creating an app!! Lets dance..

We can jumpstart on creating an Avalon app by using the template available in VC# (needs installation of the extensions). This creates a App.xaml and window.xaml file along with the corresponding .cs files.

Now that we have these files, lets create a simple RichTextBox such that every paragraph has a different color when the text is typed into the box. It looks like the following image.

(This code just attempts to show the ease of coding with Avalon. The code is not guaranteed to be perfect and optimal ;) )

-----------------------------------------------------------

App.xaml file:

<

Application x:Class="Password__textbox_RichTextBox.MyApp"

xmlns="https://schemas.microsoft.com/winfx/avalon/2005"

xmlns:x="https://schemas.microsoft.com/winfx/xaml/2005"

StartingUp="AppStartingUp">

<

Application.Resources>

</

Application.Resources>

</

Application>

(This file is created by the template)

-----------------------------------------------------------

Window1.xaml:

<

Window x:Class="Password__textbox_RichTextBox.Window1"

xmlns="https://schemas.microsoft.com/winfx/avalon/2005"

xmlns:x="https://schemas.microsoft.com/winfx/xaml/2005"  Name="win1" Background="beige" Width="400">

<

StackPanel Name="Stack1">

<

Label Content="RichTextBox" ToolTip="color codes each para"/>

<

RichTextBox Name="rtb1" TextChanged="rtb_TextChanged" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto" MaxHeight="300" MaxWidth="400" />

</StackPanel>

</Window>

(Here we have a simple RichTextBox which triggers the TextChanged event every time the text is changed)

------------------------------------------------------------------------------------

window1.xaml.cs:

void rtb_TextChanged(object sender, TextChangedEventArgs e)

{

   RichTextBox rtb = sender as RichTextBox;

   if (tp == null) //initializes TextPointer

{

rtb.SelectAll();

tp = rtb.Selection.Start;

}

   rtb.Selection.SelectWord(rtb.Selection.End);

   string str = rtb.Selection.Text;

   int lenth = str.Length;

   if (str == "") //the selection is empty which indicates that the Enter key was pressed --> new para

{

_colorIndex = ++_colorIndex % 3;

      TextRange tr = new TextRange(tp, rtb.Selection.End);

rtb.Selection.Select(tp, rtb.Selection.End);

tp = rtb.Selection.End;

}

//Following code cycles through the colors.

   if (_colorIndex == 0)

{

rtb.Selection.ApplyPropertyValue(

RichTextBox.BackgroundProperty, Brushes.LightSalmon);

}

   else if (_colorIndex == 1)

{

rtb.Selection.ApplyPropertyValue(

RichTextBox.BackgroundProperty, Brushes.LightGreen);

}

   else if (_colorIndex == 2)

{

rtb.Selection.ApplyPropertyValue(

RichTextBox.BackgroundProperty, Brushes.LightCyan);

   }

   rtb.Selection.Select(rtb.Selection.End, rtb.Selection.End); //positions cursor at end

}

----------------------------------------------------------------------------------------------------------------------

Simple !!! Build and Run!! Simple, nice looking feature made easy with the power of Avalon working with C#.

This could be a possible feature of an editor or possibly a text viewer. :).

Keep coding and keep the faith