KinkumaFramework v2

KinkumaFramework v2 is MVVM Library, integrate Prism and ReactiveProperty.

Example

Hello world sample code.
namespace HelloWorld.ViewModels
{
    using System.Reactive.Linq;
    using Codeplex.KinkumaFramework;
    using Codeplex.KinkumaFramework.Interactivity;
    using Codeplex.Reactive;

    public class MainWindowViewModel : WindowViewModelBase
    {
        // KinkumaFramework
        public readonly ReactiveErrorsContainer errorsContainer;

        // ReactiveProperty
        public ReactiveProperty<string> Input1 { get; private set; }
        public ReactiveProperty<string> Input2 { get; private set; }
        public ReactiveCommand ShowWindowCommand { get; private set; }

        // KinkumaFramework
        public ReactiveInteractionRequest<ShowMessageBoxConfirmation> MessageBoxRequest { get; private set; }

        public MainWindowViewModel()
        {
            this.Title.Value = "Hello world";

            this.Input1 = new ReactiveProperty<string>()
                .SetValidateError(s => s != "Hello" ? "Please input 'Hello'" : null);
            this.Input2 = new ReactiveProperty<string>()
                .SetValidateError(s => s != "world" ? "Please input 'world'" : null);

            // Container ReactiveProperty error.
            this.errorsContainer = new ReactiveErrorsContainer(
                this.Input1.ObserveErrorChanged,
                this.Input2.ObserveErrorChanged);

            // Create ReactiveCommand from ReactiveErrorsContainer.
            this.ShowWindowCommand = this.errorsContainer.ToReactiveCommand(false);

            // Create ReactiveInteractionRequest<Notification> from IO<Notification>.
            this.MessageBoxRequest =
                this.ShowWindowCommand
                    .Select(_ => new ShowMessageBoxConfirmation
                    {
                        Title = "確認",
                        Content = this.Input1.Value + " " + this.Input2.Value
                    })
                    .ToReactiveInteractionRequest();
        }
    }
}

MainWindow.xaml
<Window x:Class="HelloWorld.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:HelloWorld.ViewModels"
        Title="{Binding Path=Title.Value}" 
        Height="350" 
        Width="525" 
        DataContext="{Binding Source={StaticResource Locator}, Path=MainWindowViewModel}" 
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
        xmlns:my="http://www.codeplex.com/prism" 
        xmlns:my1="clr-namespace:Codeplex.KinkumaFramework.Interactivity;assembly=KinkumaFramework.NET4">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="261*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="172*" />
        </Grid.RowDefinitions>
        <i:Interaction.Triggers>
            <my:InteractionRequestTrigger SourceObject="{Binding Path=MessageBoxRequest}">
                <my1:ShowMessageBoxAction />
            </my:InteractionRequestTrigger>
        </i:Interaction.Triggers>
        <Button 
            Content="Show" 
            Command="{Binding Path=ShowWindowCommand}" 
            Grid.Row="2" 
            Grid.ColumnSpan="3" />
        <Label 
            Content="Input1" 
            Target="{Binding ElementName=textBox1}" 
            VerticalAlignment="Center" />
        <Label 
            Content="Input2" 
            Target="{Binding ElementName=textBox2}" 
            Grid.Row="1" 
            VerticalAlignment="Center" />
        <TextBox 
            Name="textBox1" 
            Text="{Binding Path=Input1.Value, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" 
            ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Mode=Self}, Path=(Validation.Errors)[0].ErrorContent}" 
            Grid.Column="1" 
            MinWidth="200" 
            Margin="5" />
        <TextBox 
            Name="textBox2" 
            Text="{Binding Path=Input2.Value, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" 
            ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Mode=Self}, Path=(Validation.Errors)[0].ErrorContent}" 
            Grid.Row="1" 
            Grid.Column="1" 
            MinWidth="200" 
            Margin="5" />
        <TextBlock 
            Grid.Column="2" 
            Text="{Binding ElementName=textBox1, Path=(Validation.Errors)[0].ErrorContent}" 
            Foreground="Red" 
            VerticalAlignment="Center" />
        <TextBlock 
            Grid.Column="2" 
            Grid.Row="1" 
            Text="{Binding ElementName=textBox2, Path=(Validation.Errors)[0].ErrorContent}" 
            Foreground="Red" 
            VerticalAlignment="Center" />
    </Grid>
</Window>

WS000016.JPG
WS000017.JPG

Last edited Oct 30, 2011 at 6:00 AM by okazuki, version 14