Last active
August 29, 2015 13:57
-
-
Save adilmughal/9775559 to your computer and use it in GitHub Desktop.
MVVM_ContactForm_WP_View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<phone:PhoneApplicationPage | |
x:Class="DemoMvvm.WP.View.ContactPage" | |
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" | |
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" | |
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="Contact Me" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> | |
<TextBlock Text="This is a sample page to demostrate MVVM implementation!" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap"/> | |
</StackPanel> | |
<!--ContentPanel - place additional content here--> | |
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> | |
<StackPanel Margin="12,17,0,28"> | |
<TextBlock Text="Name: " Style="{StaticResource PhoneTextNormalStyle}"/> | |
<TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=Explicit}" TextChanged="OnTextChangeUpdateSource" /> | |
<TextBlock Text="Email: " Style="{StaticResource PhoneTextNormalStyle}"/> | |
<TextBox Text="{Binding Email, Mode=TwoWay, UpdateSourceTrigger=Explicit}" TextChanged="OnTextChangeUpdateSource" /> | |
<TextBlock Text="Category: " Style="{StaticResource PhoneTextNormalStyle}"/> | |
<toolkit:ListPicker ItemsSource="{Binding Categories}" SelectedItem="{Binding SelectedCategory, Mode=TwoWay}"> | |
<toolkit:ListPicker.ItemTemplate> | |
<DataTemplate> | |
<StackPanel Orientation="Horizontal"> | |
<TextBlock Text="{Binding Path=Title}" /> | |
</StackPanel> | |
</DataTemplate> | |
</toolkit:ListPicker.ItemTemplate> | |
</toolkit:ListPicker> | |
<TextBlock Text="Inquiry: " Style="{StaticResource PhoneTextNormalStyle}"/> | |
<TextBox Text="{Binding Path=Inquiry, Mode=TwoWay, UpdateSourceTrigger=Explicit}" | |
TextChanged="OnTextChangeUpdateSource" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Height="128"/> | |
<Button IsEnabled="{Binding IsValid, Mode=OneWay}" Content="Submit" Command="{Binding SubmitCommand}" /> | |
</StackPanel> | |
</Grid> | |
</Grid> | |
</phone:PhoneApplicationPage> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class ContactPage : PhoneApplicationPage | |
{ | |
private readonly ContactPageViewModel _viewModel; | |
public ContactPage() | |
{ | |
this.InitializeComponent(); | |
this._viewModel = new ContactPageViewModel(); | |
this.DataContext = this._viewModel; | |
this.Loaded += this.OnPageLoaded; | |
} | |
private void OnPageLoaded(object sender, RoutedEventArgs e) | |
{ | |
this._viewModel.InitializeViewModel(); | |
} | |
private void OnTextChangeUpdateSource(object sender, TextChangedEventArgs e) | |
{ | |
var textBox = sender as TextBox; | |
if (textBox != null) | |
{ | |
BindingExpression be = textBox.GetBindingExpression(TextBox.TextProperty); | |
be.UpdateSource(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment