Brush object serialization and Isolated Storage

You probably already know that you cant serialize Brush objects using Isolated storage default serialization engine, so there are a few ways you can overcome this simple problem. There are a few approaches to solving this problem and some of them include serialization of brushes Argb byte values, or brush Color values. I’m gonna show you how to create a simple serializable class in order to overcome this problem by serializing brushes Color.

using System.Windows.Media;
using System.Runtime.Serialization;

namespace TheTime.Model
{
    [DataContract]
    public class BindableBrush
    {
        private string _brushName;
        /// <summary>
        /// Initializes a new instance of the BindableBrush class.
        /// </summary>
        public BindableBrush(Color c, string name)
        {
            Color = c;
            _brushName = name;
           
        }

        [DataMember]
        public Color Color
        { get; set; }


        public SolidColorBrush Brush 
        {
            get
            {
                return new SolidColorBrush(Color);
            }
            set
            {
                Color = value.Color;
            }
        }

        [DataMember]
        public string BrushName
        {
            get
            {
                return _brushName;
            }
            set
            {
                _brushName = value;
            }
        }
    }
}

This simple solution serializes the Color object and creates a SolidColorBrush on request. Using this class you can bind to the Brush property without any problem…

Hope it helps!

Hiding the Windows Phone 7 keyboard (SIP) when enter key is typed

There is only one way to close the SIP (Soft Input Panel) by default in Windows Phone 7, and it is by changing focus from the TextBox that is being edited to something else on the screen. As an android user, I am used to close it by hitting the enter key once the text editing is done so I’m gonna show you how to do it and hope it will become a practice.
What we need to do here is change the focus to something other than the TextBox we are currently editing, and for that purpose the PhoneApplicationPage that contains this TextBox will do just fine. All we have to do first is make this page a TabStop so we can enable it to recieve the focus.

<phone:PhoneApplicationPage 
x:Class="PanoramaPivotControls.SettingsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
IsTabStop="True">

...

</phone:PhoneApplicationPage>

Next thing to do is add the KeyUp event handler to the TextBox and implement it.

<TextBox KeyUp="TextBox_KeyUp">

 

private void TextBox_KeyUp(object sender, KeyEventArgs e)
{
     if (e.Key == Key.Enter)
     {
         this.Focus();
     }
}

 

And that’s it! The SIP is now closed when Enter key is typed in!

Hope you find it useful..