Shalvin Interests

Tuesday, July 19, 2011

INotifyPropertyChanged Interface

A change-notification handler notifies a binding target that a change has been
made. This enables a target to automatically respond to changes. Dependency properties
already have this feature built in, but CLR properties don’t. If you want your CLR
properties to broadcast their changes, you must implement the INotifyProperty-
Changed interface.

INotifyPropertyChanged interface belongs to System.ComponentModel namespace.

using System.ComponentModel;

namespace INotifyProperyChangeShalvin
{
    public class Speaker : INotifyPropertyChanged
    {
        private string mSpeakerName;
            public string SpeakerName
            {
                get { return mSpeakerName; }
                set
                {
                    mSpeakerName = value;
                    FirePropertyChanged("SpeakerName");
                }
            }
            public event PropertyChangedEventHandler PropertyChanged;


            void FirePropertyChanged(string property)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this,
                        new PropertyChangedEventArgs(property));
                }
            }
        }
    }




private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    Speaker s = new Speaker { SpeakerName = "Shalvin" };
    LayoutRoot.DataContext = s;
}


<Grid x:Name="LayoutRoot" Background="White">
        <TextBox Height="23" HorizontalAlignment="Left" Margin="120,47,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding SpeakerName, Mode=TwoWay}" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="120,147,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" Text="{Binding SpeakerName, Mode=TwoWay}" />
</Grid>

Monday, July 18, 2011

Silverlight Layout Container

Silverlight Layout Containers are panels that derive from the abstract System.Windows.Controls.Panel class. The Properties of Panel class as Background and Children.

The Layout Panels are StackPanel, WrapPanel, DockPanel, Grid and Canvas.

Wednesday, July 13, 2011

Silverlight Styles

Styles is a collection of property value you can apply to an element. In a way it is equivalent to the functionality of CSS in HTML. You store style object as a resource.

<UserControl.Resources>
    <Style x:Key="SimpleStyle" TargetType="Button">
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="Background" Value="Cyan"/>
    </Style>
</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="White">
    <Button Style="{StaticResource SimpleStyle}" Content="Button" Height="23" HorizontalAlignment="Left" Margin="50,76,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="50,137,0,0" Name="button2" VerticalAlignment="Top" Width="75" />
</Grid>

Monday, July 11, 2011

Attached Property

Attached property is a special kind of Dependency Property. Attached propety applies to a class other than one where it is defined.

The best example of Attached property is the Row and Column Properties of Grid class. You set these properties inside the elements in a Grid.

Silverlight Dependency Property

Dependency Property include a mechanism that at any point of time determines what the value of propery should be based on several incluences working on the property such as databinding, styling and so on. These multiple services are called property providers They can be considered as the enabler for animation, databinding, styling and so on.

These different properties are prioritized. Animation is having the highest priority. This prioritization process is called dynamic value resoultion.

The list is as follows :
1. Animation
2. Local value. If you set a value using Resources or data binding it is considered as locally set
3. Styles
4. Property Value Inheritance
5.Default Value

Silverlight FullScreen

private  void btnFullScreen_Click(object sender, RoutedEventArgs e)
{
Application.Current.Host.Content.IsFullScreen = true;
}

Friday, July 8, 2011

UIElement class in Silverlight

UIElement is an object that represents a visual component. These types of elements
A have built-in support for layout, event handling, and rendering.