Click here to Skip to main content
15,896,606 members
Articles / Programming Languages / C#

Updating Source on PropertyChanged on Silverlight

Rate me:
Please Sign up or sign in to vote.
4.89/5 (13 votes)
6 Jul 2010CPOL1 min read 36.7K   266   11  
A simple dependency property that allows you to update a property on PropertyChanged.
<UserControl x:Class="UpdateSourceTrigger.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:UpdateSourceTrigger"
    mc:Ignorable="d"
    >

    <UserControl.DataContext>
        <local:PersonViewModel/>
    </UserControl.DataContext>
    
    <Grid x:Name="LayoutRoot" Background="White" Width="400" Height="300" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" Text="First Name :" Grid.Column="0" Grid.Row="0"/>
            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" Text="Middle Name :" Grid.Column="0" Grid.Row="1"/>
            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" Text="Last Name :" Grid.Column="0" Grid.Row="2"/>
            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" Text="Monthly Salary :" Grid.Column="0" Grid.Row="3"/>
            <TextBox Text="{Binding Context.FirstName, Mode=TwoWay}" Grid.Column="1" Grid.Row="0" Margin="5" local:UpdateSourceManager.UpdateOnPropertyChanged="True"/>
            <TextBox Text="{Binding Context.MiddleName, Mode=TwoWay}" Grid.Column="1" Grid.Row="1" Margin="5" local:UpdateSourceManager.UpdateOnPropertyChanged="True"/>
            <TextBox Text="{Binding Context.LastName, Mode=TwoWay}" Grid.Column="1" Grid.Row="2" Margin="5" local:UpdateSourceManager.UpdateOnPropertyChanged="True"/>
            <TextBox Text="{Binding Context.Salary, Mode=TwoWay}" Grid.Column="1" Grid.Row="3" Margin="5" local:UpdateSourceManager.UpdateOnPropertyChanged="True"/>
        </Grid>
        <Button Content="Save Context..." Margin="5" Grid.Row="1" HorizontalAlignment="Right" Width="125" Command="{Binding SaveContext}"/>
    </Grid>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Brazil Brazil
Senior Software Architect from Brazil.

Comments and Discussions