Skip to content

Instantly share code, notes, and snippets.

View rootasjey's full-sized avatar

Jeremie Corpinot rootasjey

View GitHub Profile
@rootasjey
rootasjey / uwp-screenSize.cs
Created October 2, 2016 13:54
Get the screen's current size in an uwp app
using Windows.UI.ViewManagement;
using Windows.Graphics.Display;
using Windows.Foundation;
var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
var size = new Size(bounds.Width*scaleFactor, bounds.Height*scaleFactor);
@rootasjey
rootasjey / uwp-wincomposition-chaining-effects.cs
Created October 2, 2016 14:22
Chaining effects (tint color and blur) in UWP Composition
// ParallaxImage is an Image Control
// ParallaxCanvas (Canvas type) is ParallaxImag's parent
_backgroundVisual = ElementCompositionPreview.GetElementVisual(ParallaxImage);
_backgroundCompositor = _backgroundVisual.Compositor;
var color = new Windows.UI.Color() {
A = 0,
B = 250,
R = 50,
G = 90
@rootasjey
rootasjey / parallax-preview.xaml
Last active October 8, 2016 23:10
A xaml code preview about the tree construction for parallax image animation
<Grid>
<!-- Setting the parallax image inside a canvas allows the image to be larger than the screen -->
<Canvas x:Name="ParallaxCanvas">
<!-- The image we will animate -->
<Image x:Name="ParallaxImage"
Opacity="0"
ImageOpened="ParallaxImage_ImageOpened"
Loaded="ParallaxImage_Loaded"/>
</Canvas>
@rootasjey
rootasjey / parallax-preview.xaml.cs
Last active October 16, 2016 12:24
CSharp code preview for parallax image
using Windows.UI.Composition;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
private Visual _backgroundVisual;
private Compositor _backgroundCompositor;
private ScrollViewer _ListQuotesScrollViewer;
private CompositionPropertySet _ListQuotesScrollerPropertySet;
// Fire when the Image control is loaded
@rootasjey
rootasjey / VisualTreeExtension.cs
Created October 9, 2016 19:58
Retrieve XAML control from code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
@rootasjey
rootasjey / blur-preview.xaml.cs
Last active October 16, 2016 12:23
CSharp code preview for blur image
using Windows.UI.Composition;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
private Visual _backgroundVisual;
private Compositor _backgroundCompositor;
private ScrollViewer _ListQuotesScrollViewer;
private CompositionPropertySet _ListQuotesScrollerPropertySet;
// Fire when the Image control is loaded
@rootasjey
rootasjey / uwp_key_event.cs
Last active February 26, 2018 12:21
Page global keyboard event in uwp
using Windows.UI.Core;
// This sample code shows how to perform
// a navigation back on backspace key or escape key
// but the code can be adapted to any scenario
// involving keyboard event triggering an action
namespace app.Views {
public sealed partial class MainPage : Page {
@rootasjey
rootasjey / SemanticZoom.xaml
Last active March 19, 2017 21:59
uwp SemanticZoom controle sample
<SemanticZoom x:Name="SemanticZoomAuthors" IsZoomOutButtonEnabled="True" ScrollViewer.ZoomMode="Enabled">
<SemanticZoom.ZoomedOutView>
<GridView x:Name="AuthorsKeys"
SelectionMode="None"
HorizontalAlignment="Center"
Padding="30">
<GridView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Group.Key}" Width="50" FontSize="46" Margin="20" Foreground="{ThemeResource SystemControlHighlightAccentBrush}"/>
</DataTemplate>
@rootasjey
rootasjey / SemanticZoom.cs
Last active March 19, 2017 14:32
uwp Semantic Zoom c# code-behind
// This code works with SemanticZoom.xaml gist
// It show you how to bind data to a CollectionViewSource
// in order to use a SemanticView control
// NOTE: Author is a custom model I created in my code
// See the model definition here
// https://github.com/rootasjey/citations365/blob/master/Citations%20365/Citations%20365/Models/Author.cs
private void BindCollectionToView() {
// 1.You need a data list
@rootasjey
rootasjey / RegisterBackgroundTask.cs
Created March 19, 2017 17:53
Register a background task in C#
public async void RegisterBackgroundTask(string taskName, string entryPoint) {
// If the task is already registered, don't registered it again
foreach (var task in BackgroundTaskRegistration.AllTasks) {
if (task.Value.Name == taskName) {
return;
}
}
BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
if (status == BackgroundAccessStatus.DeniedBySystemPolicy ||