Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / WPF

Tasks managing app using MVVM and NHibernate

Rate me:
Please Sign up or sign in to vote.
4.71/5 (5 votes)
19 Jul 2012CPOL4 min read 27.3K   879   10  
Full sample on how to develop a MVVM desktop app with NHibernate (SQLite) backend
<UserControl x:Class="WpfApp.Views.TaskManagerView"
             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"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20" MaxHeight="20" MinHeight="20" />
            <RowDefinition />
            <RowDefinition Height="40" MaxHeight="40" MinHeight="40" />
        </Grid.RowDefinitions>
        <!-- Seleccion de dia-->
        <DatePicker Grid.Row="0"  SelectedDate="{Binding Path=SelectedDay}"/>
        <!-- Editor de Task -->
        <StackPanel Grid.Row="1" Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <Label Content="Prj"/>
                <TextBox Width="200" Text="{Binding Path=CurrentTask.TaskProject.Code}" IsEnabled="False" />
                <Button Name="btShowProjectPicker" Content="...">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ei:CallMethodAction TargetObject="{Binding}" MethodName="ShowProjectPicker"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Label FontWeight="Bold" Foreground="Red" Visibility="{Binding Path=TaskProjectInvalid}">!</Label>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="Act"/>
                <TextBox Width="200" Text="{Binding Path=CurrentTask.TaskActivity.Name}" IsEnabled="False" />
                <Button Name="btShowActivityPicker" Content="...">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ei:CallMethodAction TargetObject="{Binding}" MethodName="ShowActivityPicker"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Label FontWeight="Bold" Foreground="Red" Visibility="{Binding Path=TaskActivityInvalid}">!</Label>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="Hours"/>
                <TextBox Width="40">
                    <Binding>
                        <Binding.Path>CurrentTask.TaskHours</Binding.Path>
                        <Binding.Mode>TwoWay</Binding.Mode>
                    </Binding>
                </TextBox>
                <Label FontWeight="Bold" Foreground="Red" Visibility="{Binding Path=TaskHoursInvalid}">!</Label>
            </StackPanel>
            <ListBox MinHeight="160" ItemsSource="{Binding Path=TasksOfDay}" SelectedValue="{Binding Path=ListSelection, Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{Binding Path=TaskHours}"/>
                            <Label Content=" / "/>
                            <Label Content="{Binding Path=TaskProject.Code}"/>
                            <Label Content=" / "/>
                            <Label Content="{Binding Path=TaskActivity.Name}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <!--<i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <ei:CallMethodAction TargetObject="{Binding}" MethodName="TaskListSelectionChanged"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>-->
            </ListBox>          
        </StackPanel>
        <!-- Botones de accion-->
        <StackPanel Grid.Row="2" Orientation="Horizontal">
            <Button Content="New" IsEnabled="True" Visibility="Visible">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:CallMethodAction TargetObject="{Binding}" MethodName="CreateNewTask"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>                
            </Button>
            <Button Content="Del">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:CallMethodAction TargetObject="{Binding}" MethodName="DelCurrentTask"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Content="Save" IsEnabled="{Binding Path=SaveTaskEnabled}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:CallMethodAction TargetObject="{Binding}" MethodName="SaveCurrentTask"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Content="Report">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:CallMethodAction TargetObject="{Binding}" MethodName="ShowReportModule"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>            
        </StackPanel>
    </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
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions