Skip to content

Instantly share code, notes, and snippets.

@sonnemaf
Created September 14, 2023 08:44
Show Gist options
  • Save sonnemaf/4b4be8d12abe9a6f69504e0a2603fece to your computer and use it in GitHub Desktop.
Save sonnemaf/4b4be8d12abe9a6f69504e0a2603fece to your computer and use it in GitHub Desktop.
Uno Test App used in Twitter video
<Page x:Class="UnoApp8.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:UnoApp8"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid>
<Border Width="300"
Height="200"
Background="Red"
CornerRadius="8"
PointerExited="Rectangle_PointerReleased"
PointerMoved="Rectangle_PointerMoved"
PointerPressed="Rectangle_PointerPressed"
PointerReleased="Rectangle_PointerReleased"
RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<CompositeTransform x:Name="rectTransform" />
</Border.RenderTransform>
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="44"
Foreground="White"
Text="Uno Platform" />
</Border>
</Grid>
</Page>
using Microsoft.UI;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Shapes;
using Windows.Foundation;
namespace UnoApp8 {
public sealed partial class MainPage : Page {
private bool _isDown;
private Point _orgPoint;
public MainPage() {
this.InitializeComponent();
}
private void Rectangle_PointerMoved(object sender, PointerRoutedEventArgs e) {
if (_isDown && sender is Border border) {
border.Background = new SolidColorBrush(Colors.Orange);
var p = e.GetCurrentPoint(null).Position;
rectTransform.TranslateX = -(_orgPoint.X - p.X);
rectTransform.TranslateY = -(_orgPoint.Y - p.Y);
}
}
private void Rectangle_PointerReleased(object sender, PointerRoutedEventArgs e) {
if (_isDown && sender is Border border) {
border.Background = new SolidColorBrush(Colors.Red);
_isDown = false;
}
}
private void Rectangle_PointerPressed(object sender, PointerRoutedEventArgs e) {
if (sender is Border border) {
border.Background = new SolidColorBrush(Colors.Blue);
_isDown = true;
_orgPoint = e.GetCurrentPoint(null).Position;
_orgPoint.X -= rectTransform.TranslateX;
_orgPoint.Y -= rectTransform.TranslateY;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment