Belajardengan.com merupakan domain blog lama dari delajardengan.blogspot.com. Mohon kritik dan sarannya untuk perkembangan blog ini.
email: blog.tkx.pnp@gmail.com

Windows Phone || INotifyPropertyChanged

♠ Posted by Unknown in at 8:40 AM

INotifyPropertyChanged


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace PhoneApp2
{
    class DataBinding2 : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private int _nama,_a,_b,_c;
        public int Nama {
            get {
                return _nama;
            }
            set {
                _nama = value;
                _nama = _nama * 5;
                berubah("Nama");
            }
        }

        public int A {
            get
            {
                return _a;
            }
            set
            {
                _a = value;
                berubah("");
            }
        }

        public int B
        {
            get
            {
                return _b;
            }
            set
            {
                _b = value;
                berubah("");
            }
        }

        public int C
        {
            get
            {
                return _c=_a+_b;
            }
            set
            {
                _c = value;
                berubah("");
            }
        }
        void berubah(string a) {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(a));
            }
        }
    }
}



------------------


<phone:PhoneApplicationPage
    x:Class="PhoneApp2.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Button" HorizontalAlignment="Left" Margin="153,31,0,0" VerticalAlignment="Top" />
            <TextBox Text="{Binding Nama}" HorizontalAlignment="Left" Height="72" Margin="0,133,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="456"/>
            <TextBox HorizontalAlignment="Left" Height="72" Margin="0,205,0,0" TextWrapping="Wrap" Text="{Binding A, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
            <TextBox HorizontalAlignment="Left" Height="72" Margin="0,265,0,0" TextWrapping="Wrap" Text="{Binding B, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
            <TextBox HorizontalAlignment="Left" Height="72" Margin="0,342,0,0" TextWrapping="Wrap" Text="{Binding C, Mode=TwoWay}" VerticalAlignment="Top" Width="456"/>
        </Grid>
        <Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </Grid>

</phone:PhoneApplicationPage>




0 komentar:

Post a Comment