4. Metro styles or Windows Phone Design Style?
• The Windows Phone team have taken a lot of
trouble over the look and feel of the phone
• They have created a design style, inspired by
metropolitan signage, to express this
• Programs on the phone should reflect this style
4
5.
6. Take care of the details
Make it safe and reliable
Uncompromising Sensitivity to Weight, Balance and Scale
Align to the grid
7. Principle: Be fast and fluid
Life is mobile
Delight with motion
Design for touch
Intuitive interaction
Be responsive and ready
Immersive and compelling
8. Principles: Do more with less
Be great at something
Focused and direct
Content before chrome
Inspire confidence
31. XAML Element Class Hierarchy
• The XAML class hierarchy is
quite complex
• Everything is based on the
FrameworkElement class which
contains the fundamental properties
of all elements
• You can derive your own components
if you wish
31
FrameworkElement
TextBlock
TextBox ContentControl
ButtonBase
Button
Control
35. • Button at bottom of Designer window can be
used to show a 12px alignment Grid
• Useful for setting alignment of elements
• Available in Blend
• Now also available in Visual Studio
Visual Studio and Blend Alignment Grid
8/16/2014 35
36. • All new projects include AlignmentGrid.png in the Assets folder
• You can overlay the grid at design and runtime by uncommenting
the XAML that shows it
• Included near the foot of MainPage.xaml
• Copy to other pages to show on those
<!--Uncomment to see an alignment grid to help ensure your controls are
aligned on common boundaries. The image has a top margin of -32px to
account for the System Tray. Set this to 0 (or remove the margin altogether)
if the System Tray is hidden.
Before shipping remove this XAML and the image itself.-->
<!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0"
Grid.RowSpan="2" IsHitTestVisible="False" />-->
Alignment Grid Overlay
36
37. Using the Alignment Grid
8/16/2014 37
<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top"
Height="800" Width="480" Margin="0,-32,0,0"
Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />
41. • You can set colors and font sizes for elements directly in XAML:
<ScrollViewer Grid.Row="1">
<TextBlock x:Name="DirectionsTextBlock" TextWrapping="Wrap"
Margin="12,0,0,0" Foreground="White" FontSize="12" />
</ScrollViewer>
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="12" HorizontalAlignment="Left" >
<TextBlock Text="Prep time: " Margin="0" Foreground="White"/>
<TextBlock x:Name="PrepTimeTextBlock" Foreground="LightGray" FontSize="24" />
</StackPanel>
• This is generally a BAD IDEA!
• Difficult to match builtin styles
• Difficult to work with Windows Phone Themes
Applying Styles to Elements
8/16/2014 41
50. Commands
“Point of entry” for a method Can be data
bound
ICommand interface
Execute method
CanExecute method
CanExecuteChanged event
51. Implementing commands
It’s quite a lot of work
Most toolkits and frameworks have a “relay”
implementation
RelayCommand (MVVM Light)
DelegateCommand (PRISM)
…
52. Why MVVM?
Model
public class KittenObject
{
public KittenObject() { }
public string KittenImage { get; set; }
public string KittenName { get; set; }
public string KittenAge { get; set; }
}
53. Why MVVM?
ViewModel
public class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
54. Why MVVM?
ViewModel
private string _sampleProperty = "my start value";
public string SampleProperty
{
get { return _sampleProperty; }
set
{
_sampleProperty = value;
NotifyPropertyChanged("SampleProperty");
}
}
58. Data Binding Modes
• The Mode property determines how changes
are synchronized between the target control and
data source
• OneTime – Control property is set once to the data value
and any subsequent changes are ignored
• OneWay – Changes in the data object are synchronized to
the control property, but changes in the control are not
synchronized back to the data object
• TwoWay – Changes in the data object are synchronized to
the control property and vice-versa
<TextBlock x:Name="ContentText"
Text="{Binding LineThree, Mode=OneWay}"/>
59. • In the XAML snippet, make sure
that the DataContext is set to an
instance of the ViewModel class.
• The ViewModel class exposes an
AddCommand property of type
AddItemCommand
• The ViewModel is responsible for
actually adding a new item
Commands
<Button Command="{Binding AddCommand}"
CommandParameter="Untitled" Content="Button"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
class AddItemCommand : ICommand
{
ViewModel _viewModel;
public AddItemCommand(ViewModel viewModel)
{
_viewModel = viewModel;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object title)
{
_viewModel.AddItem(title as string);
}
}
60. MVVM Benefits
• Reuse Model and View-Model code
• Test the ViewModel with unit tests
• Maintainability
• Can show design-time data in Expression Blend
and the Visual Studio designer
74. Review
• Windows Phone Design has five key principles:
• Clean, Light, Open, Fast
• Celebrate Typography
• Alive in Motion
• Content, Not Chrome
• Authentically Digital
• WP8 use XAML to express the design of their user interface
• The design is expressed in a XAML text file that defines and arranges display elements
• There are a set of project templates for applications based on the Windows
Phone design
• In Blend, you can create design-time data to aid during design of a UI
• Databinding in XAML allows you to declaratively markup UI elements to link
them to a property of a data class
• List controls define layout using XAML Templates