Click here to Skip to main content
15,891,905 members
Articles / Desktop Programming / WPF

MVVM for Multi Platforms

Rate me:
Please Sign up or sign in to vote.
4.13/5 (6 votes)
22 Mar 2010CPOL2 min read 26.4K   354   22  
How to implement MVVM when developing a view model whose view implementation language is not certain
<Window x:Class="GeographicRepresentation.UILib.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:GeographicRepresentation.UILib.View"
    xmlns:me="clr-namespace:GeographicRepresentation.UILib"    
    Title="Geographic representation" WindowState="Maximized"
    Loaded="Window_Loaded">
    <Grid>
        <Grid.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="View/CommonViewDictionary.xaml" />
                </ResourceDictionary.MergedDictionaries>            
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Margin" Value="20,10,20,10" />
                    <Setter Property="Height" Value="30" />
                    <Setter Property="Width" Value="45" />
                    <Setter Property="HorizontalAlignment" Value="Left" />                
                </Style>
                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource textBlockStyle}" />
            </ResourceDictionary>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <DockPanel Background="LightGray" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0">            
            <Menu Height="30" Width="45" HorizontalAlignment="Left" Margin="20,10,20,10">
                <MenuItem Height="30" 
                          HorizontalAlignment="Stretch" 
                          >
                    <MenuItem.HeaderTemplate>
                        <DataTemplate>
                            <DockPanel>
                                <TextBlock Text="New" VerticalAlignment="Center" />
                                <Canvas Height="10" Width="10">                                    
                                    <Polygon Points="1,3 10,3, 5,10" Fill="Black" />
                                </Canvas>
                            </DockPanel>
                        </DataTemplate>
                    </MenuItem.HeaderTemplate>
                    <MenuItem Header="Continent" Command="me:MainWindow.cmd_AddContinent" />
                    <MenuItem Header="Country" Command="me:MainWindow.cmd_AddCountry" />
                    <MenuItem Header="City" Command="me:MainWindow.cmd_AddCity" />
                </MenuItem>
            </Menu>
            <Button Content="Edit" Command="me:MainWindow.cmd_EditObject" />
            <Button Content="Delete" Command="me:MainWindow.cmd_RemoveObject" />
        </DockPanel>
        <local:ContinentsViewGrid x:Name="treeView" Grid.Column="0" Grid.Row="1" />  
        <local:SelectedObjectView Grid.Column="1" Grid.Row="1" DataContext="{Binding ElementName=treeView, Path=SelectedObject}" />
        <TextBlock x:Name="txtCurrentTime"
                   Text="{Binding Path=CurrentTime}" 
                   Grid.Row="2" Grid.Column="1"
                   HorizontalAlignment="Right"
                   VerticalAlignment="Bottom"/>
    </Grid>
</Window>

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
Israel Israel
Software Developer in a promising Clean-Tech company

Comments and Discussions