Hola!
De cara a hablar un poco sobre la forma de crear menús avanzados para el Surface Dial, retomare mi vista con el mapa y agregare 2 funcionalidades a la misma
- Utilizar el spin de Surface Dial para controlar el zoom del mapa
- Utilizar el spin de Surface Dial para rotar la vista actual en el mapa
El 1er ejemplo lo comente en el post anterior, hoy mostrare la 2da funcionalidad.
El código para trabajar la misma es muy simple. Se basa en lo siguiente
- Para brindar las 2 funcionalidades con el Surface Dial, el clic en el dial, cambia el modo de Zoom a Rotate y nuevamente a zoom
- En el evento RotationChanged() se verifica el modo de trabajo y se aplican los cambios sobre el mapa
Muy simple.
enum ControllerMode { zoom, rotate }; | |
ControllerMode _controllerMode; | |
readonly RadialController _controller; | |
public MapPagePage() | |
{ | |
locationService = new LocationService(); | |
Center = new Geopoint(defaultPosition); | |
ZoomLevel = DefaultZoomLevel; | |
InitializeComponent(); | |
_controller = RadialController.CreateForCurrentView(); | |
_controller.RotationResolutionInDegrees = 0.2; | |
_controller.UseAutomaticHapticFeedback = false; | |
var myItem = RadialControllerMenuItem.CreateFromFontGlyph("El Bruno – Maps", "\xE128", "Segoe MDL2 Assets"); | |
_controller.Menu.Items.Add(myItem); | |
_controller.ButtonClicked += ControllerButtonClicked; | |
_controller.RotationChanged += ControllerRotationChangedAsync; | |
} | |
private async void ControllerRotationChangedAsync(RadialController sender, RadialControllerRotationChangedEventArgs args) | |
{ | |
Debug.WriteLine($"{args.RotationDeltaInDegrees}"); | |
if (_controllerMode == ControllerMode.zoom) | |
mapControl.ZoomLevel = mapControl.ZoomLevel + args.RotationDeltaInDegrees; | |
else | |
await mapControl.TryRotateAsync(args.RotationDeltaInDegrees); | |
} | |
private void ControllerButtonClicked(RadialController sender, RadialControllerButtonClickedEventArgs args) | |
{ | |
if (_controllerMode == ControllerMode.rotate) | |
_controllerMode = ControllerMode.zoom; | |
else | |
_controllerMode = ControllerMode.rotate; | |
} |
En el próximo post, un poco sobre como trabajar con el menú que nos ofrece el Surface Dial.
Happy Coding!
Source Code en GitHub
Saludos @ Toronto
El Bruno
References
- El Bruno, 2 lines of C# code to handle maps using a Surface Dial
- El Bruno, Controlling a Media Player Element with Surface Dial in a Windows Store App
- El Bruno, Kind of a Hello World with a Surface Dial in a Windows Store App
- Windows Dev Center, Surface Dial Interactions
- Canadian Developer Connection, Developing for Surface Dial
- Visual Studio MarketPlace, Windows Template Studio