Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / WPF

AutoPropertyChanged - Type-safe INotifyPropertyChanged Implementation

Rate me:
Please Sign up or sign in to vote.
3.54/5 (11 votes)
24 May 2010CPOL6 min read 35K   227   14  
Typesafe INotifyPropertyChanged implementation without run-time Reflection and without lambda expressions.
<UserControl x:Class="AutoPropertyChangedDemo.Views.LeftView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="136" />
        </Grid.RowDefinitions>
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBlock1" Text="Some ListView items:" VerticalAlignment="Top" />
        <ListView Margin="12,41,12,0" Name="listView1" ItemsSource="{Binding Path=ListViewItems}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="100" Header="Checked?" CellTemplate="{StaticResource CheckboxColumnTemplate}" />
                    <GridViewColumn Width="160" Header="Text" DisplayMemberBinding="{Binding Path=MyText.Value}" />
                </GridView>
            </ListView.View>
        </ListView>
        <CheckBox Content="1st checkbox" Grid.Row="1" Height="16" HorizontalAlignment="Left" Margin="12,14,0,0" Name="checkBox1" VerticalAlignment="Top" IsChecked="{Binding Path=CheckBox1Selected.Value}"/>
        <CheckBox Content="2nd checkbox" Grid.Row="1" Height="16" HorizontalAlignment="Left" Margin="12,36,0,0" Name="checkBox2" VerticalAlignment="Top" IsChecked="{Binding Path=CheckBox2Selected.Value}" />
        <Slider Grid.Row="1" Height="23" Margin="12,90,12,0" Name="slider1" VerticalAlignment="Top" Value="{Binding Path=SliderPosition.Value}" Maximum="100" />
        <TextBlock Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="12,61,0,0" Name="textBlock2" Text="And another gadget:" VerticalAlignment="Top" />
    </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
Germany Germany
I am working with computers for quite a long time now, starting with BASIC on an old "Acorn Electron".

Then i continued with C and moved quickly on to C++ with some Java in the mean time.

Now, my personal favorite is C# and i love especially WPF and its versatileness, as well as the TPL. I'm still on a quite steep learning curve, but thanks to this community (among others of course Smile | :) ) i'm doing okay.

Comments and Discussions