Thursday, January 19, 2012

How to set textbox focus in silverlight using MVVM

The question has been asked a couple of times, unfortunately the answers only apply to WPF. Anyone know how to accomplish this in silverlight? Basically I need to focus on a certain textbox from code.

Following class is required in view model

public class FocusBehavior : Behavior
    {

        protected override void OnAttached()
        {
            AssociatedObject.GotFocus += (sender, args) => IsFocused = true;
            AssociatedObject.LostFocus += (sender, a) => IsFocused = false;
            AssociatedObject.Loaded += (o, a) => { if (HasInitialFocus || IsFocused) AssociatedObject.Focus(); };

            base.OnAttached();
        }

        public static readonly DependencyProperty IsFocusedProperty =
            DependencyProperty.Register(
                "IsFocused",
                typeof(bool),
                typeof(FocusBehavior),
                new PropertyMetadata(false, (d, e) => { if ((bool)e.NewValue) ((FocusBehavior)d).AssociatedObject.Focus(); }));

        public bool IsFocused
        {
            get { return (bool)GetValue(IsFocusedProperty); }
            set { SetValue(IsFocusedProperty, value); }
        }

        public static readonly DependencyProperty HasInitialFocusProperty =
            DependencyProperty.Register(
                "HasInitialFocus",
                typeof(bool),
                typeof(FocusBehavior),
                new PropertyMetadata(false, null));

        public bool HasInitialFocus
        {
            get { return (bool)GetValue(HasInitialFocusProperty); }
            set { SetValue(HasInitialFocusProperty, value); }
        }
    }

Add name space reference in Xaml file like as
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 

and give initial value and binding value like as below
 <TextBlock Height="20" HorizontalAlignment="Left" Margin="10,16,0,0" Text="Sales Order No" TextWrapping="Wrap" VerticalAlignment="Top" Width="91" />
        <TextBox Height="22"  HorizontalAlignment="Left" Margin="115,13,0,0" MaxLength="20" Name="txtSalesOrderNo" TabIndex="0"  TextWrapping="Wrap" VerticalAlignment="Top" Width="165" Text="{Binding Path=SaleOrderNo, Mode=TwoWay}" >
            <i:Interaction.Behaviors>
                <Local1:FocusBehavior HasInitialFocus="False" IsFocused="{Binding SaleOrderFocus, Mode=TwoWay}"/>
            </i:Interaction.Behaviors>


        </TextBox> 

How to set focus to a text box in silver light application

In Microsoft silver light you can set focus to the text in following way.

private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (App.Current.IsRunningOutOfBrowser)
            {
                txtSalesOrderNo.Focus(); 
            }
            else
            {
                System.Windows.Browser.HtmlPage.Plugin.Focus();
                txtSalesOrderNo.Focus(); 
            }

        }

Wednesday, January 18, 2012

How to use systax highlighter in your blog?


Introduction



I've been using Blogger as my blogging engine for a couple of weeks. I've been quite impressed at how easy it makes it to update your blogs look and feel and how free you are with the HTML and semantic layout of the pages.

One thing that seemed to be missing was allowing developers to copy and paste code into their blogs and allow other users to copy and paste the code from the blog into their own code.



Using SyntaxHighlighter Javascript Library

So in my search to find something better i came across this post which uses syntax highlighte


Adding Syntax Highlighter to Blogger Template



  • Copy the following code
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>  
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script>  <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'></script>  
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'></script>  
<script language='javascript'>  SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf'; SyntaxHighlighter.all(); </script>

  • paste it into your Blogger Template just above the </head> tag
  • Save the template
  • Then you can start creating code blocks in your existing or new Blog entries.
  • There are 2 ways to add a code block using syntaxhighlighter

<

Method 1: Using the script Tag

]]>



becomes:







Method 2: Using the pre Tag





becomes:



// Comment
public class Testing {
    public Testing() {
    }
 
    public void Method() {
        /* Another Comment
           on multiple lines */
        int x = 9;
    }
}


Code Containing Less that or Greater than

One person noticed that if you try and publish any code with < or > in it, you'll need to HTML Encode the code before adding it to the blog post using something like this. Then you'll be able to publish code with generic's such as the following:



static Dictionary<int, List<Delegate>> _delegate = new Dictionary<int, List<Delegate>>();


Conclusion

I have to say i'm pretty impressed. There are a couple of things you have to watch out for:

  • The java script uses the <code> Tag. So as lots of blogger templates have styles for this tag you have to remove any styles before it looks like the above.
  • If you paste in HTML or XML with <Tags>. You'll need to HTML encode them. Which is a bit of a shame, as i was hoping the CDATA would help get around that problem. Maybe in the next version.

How to set column alignment in silverlight Data Grid?

In Xaml write as below.
<sdk:DataGridTextColumn Binding="{Binding Path=PriceAmt}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Price Amount" IsReadOnly="True">
       <sdk:DataGridTextColumn.CellStyle>
         <Style TargetType="sdk:DataGridCell">
            <Style.Setters>
              <Setter Property="HorizontalAlignment" Value="Right"></Setter>
                 <Setter Property="FontWeight" Value="Bold" />
                     </Style.Setters>
                        </Style>
                        </sdk:DataGridTextColumn.CellStyle>
                        
</sdk:DataGridTextColumn>

Sunday, August 28, 2011

How to set windows user's password

If you want to change user password in windows, please follow the below steps.

1 - Open the "control panel"
2 - Click the "user account "
3 - Click set up a new account on the user account windows and then input a user name that you must remember it. Click "next" and select "computer administrator" option, then set up a account. In this way, you have a user name. From next step, you start to set up a password.
4 - Following above steps, clicking "changing account " and "set up password", then fill out the form as listed. Click "create password".
thus, you have a personal login id and password, any one has no right to login to your computer with out this info.

How to add master page in ASP.net web form


Master pages give your site a steady look and feel

Master pages contain both HTML and a code part

They create a common template that can be used on many pages

Updating the master page automatically updates all pages using it

A master page has 2 parts

1. Content that appears on each page that inherits the master page
2. Regions that can be customized by the pages inheriting the master page

Master pages can contain HTML, Web controls and server side source code

* Open Visual Studio
* Add a new item
* Select Master Page
Master pages end with .Master

BY default visual studio names the master page masterPage.master

A Master page need to specify both the parts common to all pages and the parts that are customizable

Items you add to the master page appear on all pages that inherit it

Use contentPlaceHolder controls to specify a region that can be customized

Add a table to the Master page
It adds on ContentPlaceHolder by default

If you place controls outside the content placeholders they will be displayed on all pages

You can have multiple contentPlaceHolder controls

Each contentPlaceHolder control can be used to customize the ASP.Net page that inherits the master page

* Add a new item
* Select Web form
* Check Select Master Page checkbox

All masterpages in your site will appear

Monday, August 16, 2010

Removing/Resetting Window XP Administrator password

EASIEST WAY TO RESET YOUR LOST PASSWORD IN WINDOWS XP

There are two methods to remove/reset the lost password of your PC in Windows XP e.g.

(i) By Parallel Windows installation.
(ii) By Using Password recovery CD.

By Parallel Windows installation
If you have lost your Windows XP Administrator’s Password and the only login User was Administrator on your computer’s Windows XP then Following is the Procedure to remove password for getting Access to your Computer:

1. First of all take another Hard Disk and install fresh Windows XP on it.
2. Place that new Hard Disk in the PC which contains the Windows XP which is locked.
3. Now start your Computer and Boot from the new Hard Disk (Fresh Windows XP)
4. Go to the Drive on which Locked Windows was installed.
5. Go to WINDOWS -> system32 -> config folder.
6. From config folder DELETE the file named SAM.
7. Then again go to WINDOWS -> repair folder.
8. From repair folder, copy SAM (and if SAM.Log file exists) file and paste the file (s) into WINDOWS -> system32 -> config folder.
9. You have removed your old Windows Password. (Hurrah!!!)

By Using Password recovery CD

1. Go to your Computer’s Boot Sequence change the boot from hard derives to CD.
2. Place Password Recover CD into your CD Rom.
3. Boot from CD and their will be set to recover/reset Password Setup.
4. Change your PC’s Password.