Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C#

Silverlight and the Unity Container - Property and Method Injection

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
28 Aug 2009CPOL1 min read 20.6K   9  
Using Property and Method injection with Silverlight 3
<UserControl x:Class="PropertyInjection.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" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Column="1" Grid.Row="0" Text="Adding two numbers using Binding and Property Injection" TextDecorations="Underline" FontWeight="Normal" FontSize="12" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.ColumnSpan="5"/>

        <TextBox x:Name="num1" Text="{Binding Mode=TwoWay, Path=NumA}" MaxLength="4" Grid.Column="0" Grid.Row="1" FontWeight="Normal" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        <TextBox Text="+" Grid.Column="1" IsReadOnly="True" Grid.Row="1" MaxLength="1" FontWeight="Normal" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        <TextBox x:Name="num2" Text="{Binding Mode=TwoWay, Path=NumB}" MaxLength="4" Grid.Column="2" Grid.Row="1" FontWeight="Normal" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        <Button Content="=" Grid.Column="3" Grid.Row="1" Height="30" Width="30" VerticalAlignment="Bottom"/>
        <TextBox x:Name="txtBlock" Text="{Binding Sum}" MaxLength="6" IsReadOnly="True" Grid.Column="4" Grid.Row="1" FontWeight="Normal" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center"/>
    </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
Software Developer (Senior)
India India

Comments and Discussions