CodePaste Logo
New Snippet New Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: csharp

Blog - WIndows 8.1 Timer Control

717 Views   
<Page.Resources> <Common:NegativeConverter x:Key="NegativeConverter"/> </Page.Resources> <Page.DataContext> <local:ViewModel/> </Page.DataContext> <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <Grid Width="400" Height="400"> <!-- ring --> <Common:RingSlice InnerRadius="100" Radius="150" Fill="#FFEC288A" StartAngle="0" EndAngle="{Binding Angle}" /> <!-- thing --> <Grid RenderTransformOrigin="0.5,0.5"> <Grid.RenderTransform> <CompositeTransform Rotation="{Binding Angle}"/> </Grid.RenderTransform> <Path Width="60" Height="100" VerticalAlignment="Top" HorizontalAlignment="Center" Stretch="Fill" Fill="#FFFFFFFF" Data="F1 M 254,99C 298.735,99 335,135.265 335,180C 335,224.735 253,349.667 253,349.667C 253,349.667 173,224.735 173,180C 173,135.265 209.265,99 254,99 Z "/> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="18" Foreground="Black" RenderTransformOrigin="0.5,0.5"> <TextBlock.Inlines> <Run Text="{Binding Value}" /> m </TextBlock.Inlines> <TextBlock.RenderTransform> <CompositeTransform TranslateY="17" Rotation="{Binding Angle, Converter={StaticResource NegativeConverter}}"/> </TextBlock.RenderTransform> </TextBlock> </Grid> <!-- touch grid --> <Grid Background="Transparent" ManipulationMode="TranslateX,TranslateY" ManipulationDelta="Grid_ManipulationDelta" > <Grid.Clip> <RectangleGeometry Rect="150,0,100,100"> <RectangleGeometry.Transform> <CompositeTransform Rotation="{Binding Angle}" CenterX="200" CenterY="200" /> </RectangleGeometry.Transform> </RectangleGeometry> </Grid.Clip> </Grid> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="32" Foreground="Gray"> <Run Foreground="White" Text="12" />h <Run Foreground="White" Text="{Binding Value}" />m </TextBlock> </Grid> </Grid> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } private void Grid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { var grid = sender as Grid; var angle = GetAngle(e.Position, grid.RenderSize); (this.DataContext as ViewModel).Angle = angle; } public enum Quadrants : int { nw = 2, ne = 1, sw = 4, se = 3 } private double GetAngle(Point touchPoint, Size circleSize) { var _X = touchPoint.X - (circleSize.Width / 2d); var _Y = circleSize.Height - touchPoint.Y - (circleSize.Height / 2d); var _Hypot = Math.Sqrt(_X * _X + _Y * _Y); var _Value = Math.Asin(_Y / _Hypot) * 180 / Math.PI; var _Quadrant = (_X >= 0) ? (_Y >= 0) ? Quadrants.ne : Quadrants.se : (_Y >= 0) ? Quadrants.nw : Quadrants.sw; switch (_Quadrant) { case Quadrants.ne: _Value = 090 - _Value; break; case Quadrants.nw: _Value = 270 + _Value; break; case Quadrants.se: _Value = 090 - _Value; break; case Quadrants.sw: _Value = 270 + _Value; break; } return _Value; } } public class ViewModel : System.ComponentModel.INotifyPropertyChanged { public ViewModel() { if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { Angle = 45; } } double m_Angle = default(double); public double Angle { get { return m_Angle; } set { SetProperty(ref m_Angle, value); Value = (int)(value / 6d); } } int m_Value = default(int); public int Value { get { return m_Value; } private set { SetProperty(ref m_Value, value); } } public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; protected void SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] String propertyName = null) { if (!object.Equals(storage, value)) { storage = value; if (PropertyChanged != null) PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); } } protected void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] String propertyName = null) { if (PropertyChanged != null) PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); } }
by Jerry Nixon
  August 15, 2013 @ 2:15pm
Tags:
Add a comment


Report Abuse
brought to you by:
West Wind Techologies