Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Samples/Input/cs-winui/DeviceCapabilities.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Copyright (c) Microsoft Corporation.
Licensed under the MIT License. -->
<Page
x:Class="Input.DeviceCapabilities"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<ScrollViewer VerticalScrollMode="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel Margin="12,10,12,12">
<TextBlock Text="Description:" Style="{StaticResource SubtitleTextBlockStyle}"/>
<TextBlock Style="{StaticResource BodyTextBlockStyle}" TextWrapping="Wrap" Margin="0,8,0,0">
This scenario demonstrates how to use the KeyboardCapabilities, MouseCapabilities, and TouchCapabilities classes to determine what type of input the current device an app is running on supports.
</TextBlock>
<TextBlock x:Name="keyboardHeader" Text="Keyboard Properties" Style="{StaticResource SubtitleTextBlockStyle}" Padding="0,12,0,0"/>
<TextBlock x:Name="keyboardText"/>
<TextBlock x:Name="mouseHeader" Text="Mouse Properties" Style="{StaticResource SubtitleTextBlockStyle}" Padding="0,12,0,0"/>
<TextBlock x:Name="mouseText"/>
<TextBlock x:Name="touchHeader" Text="Touch Properties" Style="{StaticResource SubtitleTextBlockStyle}" Padding="0,12,0,0"/>
<TextBlock x:Name="touchText"/>
</StackPanel>
</ScrollViewer>
</Page>
35 changes: 35 additions & 0 deletions Samples/Input/cs-winui/DeviceCapabilities.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text;
using Microsoft.UI.Xaml.Controls;
using Windows.Devices.Input;

namespace Input
{
public sealed partial class DeviceCapabilities : Page
{
public DeviceCapabilities()
{
this.InitializeComponent();

KeyboardCapabilities kbdCapabilities = new KeyboardCapabilities();
keyboardText.Text = "Keyboard present = " + kbdCapabilities.KeyboardPresent.ToString();

MouseCapabilities mouseCapabilities = new MouseCapabilities();
StringBuilder sb = new StringBuilder();
sb.Append("Mouse present = " + mouseCapabilities.MousePresent.ToString() + "\n");
sb.Append("Number of buttons = " + mouseCapabilities.NumberOfButtons.ToString() + "\n");
sb.Append("Vertical wheel present = " + mouseCapabilities.VerticalWheelPresent.ToString() + "\n");
sb.Append("Horizontal wheel present = " + mouseCapabilities.HorizontalWheelPresent.ToString() + "\n");
sb.Append("Buttons swapped = " + mouseCapabilities.SwapButtons.ToString());
mouseText.Text = sb.ToString();

TouchCapabilities touchCapabilities = new TouchCapabilities();
sb = new StringBuilder();
sb.Append("Touch present = " + touchCapabilities.TouchPresent.ToString() + "\n");
sb.Append("Touch contacts supported = " + touchCapabilities.Contacts.ToString());
touchText.Text = sb.ToString();
}
}
}
31 changes: 31 additions & 0 deletions Samples/Input/cs-winui/Input.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
</PropertyGroup>
<ItemGroup>
<None Remove="DeviceCapabilities.xaml" />
<None Remove="GestureRecognizer.xaml" />
<None Remove="GestureRecognizerManipulation.xaml" />
<None Remove="InputCursor.xaml" />
<None Remove="PointerEllipse.xaml" />
<None Remove="PointerPointProperties.xaml" />
<None Remove="PointerTracking.xaml" />
<None Remove="XamlManipulations.xaml" />
</ItemGroup>

<ItemGroup>
Expand All @@ -30,6 +35,7 @@
<Content Include="Assets\SplashScreen.png" />
<Content Include="Assets\Square150x150Logo.png" />
<Content Include="Assets\Square44x44Logo.png" />
<Content Include="Assets\Landscape.jpg" />
<Content Include="Assets\logo.png" />
<Content Include="Assets\Wide310x150Logo.png" />
<Content Include="Assets\windows-sdk.ico" />
Expand All @@ -41,6 +47,11 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<Page Update="DeviceCapabilities.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="InputCursor.xaml">
<Generator>MSBuild:Compile</Generator>
Expand All @@ -56,4 +67,24 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="PointerTracking.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="PointerEllipse.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="PointerPointProperties.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="XamlManipulations.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>
54 changes: 54 additions & 0 deletions Samples/Input/cs-winui/PointerEllipse.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!-- Copyright (c) Microsoft Corporation.
Licensed under the MIT License. -->
<UserControl
x:Class="Input.PointerEllipse"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="120"
d:DesignWidth="120"
mc:Ignorable="d">

<UserControl.Resources>
<Storyboard x:Name="PrimaryPointerStoryboard">
<DoubleAnimation
Storyboard.TargetName="ellipse"
Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
Duration="0:0:1"
AutoReverse="True"
RepeatBehavior="Forever"
From="1.0"
To="1.4" />
<DoubleAnimation
Storyboard.TargetName="ellipse"
Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
Duration="0:0:1"
AutoReverse="True"
RepeatBehavior="Forever"
From="1.0"
To="1.4" />
<ColorAnimation
Storyboard.TargetName="ellipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
Duration="0:0:1"
AutoReverse="True"
RepeatBehavior="Forever"
From="White"
To="Red"
EnableDependentAnimation="True" />
</Storyboard>
</UserControl.Resources>

<Grid>
<Ellipse x:Name="ellipse"
Width="{x:Bind Diameter}"
Height="{x:Bind Diameter}"
StrokeThickness="2"
RenderTransformOrigin="0.5,0.5">
<Ellipse.RenderTransform>
<ScaleTransform ScaleX="1" ScaleY="1" />
</Ellipse.RenderTransform>
</Ellipse>
</Grid>
</UserControl>
52 changes: 52 additions & 0 deletions Samples/Input/cs-winui/PointerEllipse.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.UI;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;

namespace Input
{
public sealed partial class PointerEllipse : UserControl
{
private bool primaryEllipse;

public PointerEllipse()
{
this.InitializeComponent();
ApplyPointerStyle(false);
}

public uint PointerId { get; set; }

public bool PrimaryPointer { get; set; }

public bool PrimaryEllipse
{
get => primaryEllipse;
set
{
primaryEllipse = value;
ApplyPointerStyle(value);
}
}

public double Diameter => 120.0;

private void ApplyPointerStyle(bool isPrimary)
{
if (isPrimary)
{
ellipse.Fill = new SolidColorBrush(Colors.White);
ellipse.Stroke = new SolidColorBrush(Colors.Red);
PrimaryPointerStoryboard.Begin();
}
else
{
PrimaryPointerStoryboard.Stop();
ellipse.Fill = new SolidColorBrush(Colors.LightSkyBlue);
ellipse.Stroke = new SolidColorBrush(Colors.DodgerBlue);
}
Comment on lines +36 to +49
}
}
}
29 changes: 29 additions & 0 deletions Samples/Input/cs-winui/PointerPointProperties.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Copyright (c) Microsoft Corporation.
Licensed under the MIT License. -->
<Page
x:Class="Input.PointerPointProperties"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Margin="12,10,12,12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<ScrollViewer MaxHeight="150" VerticalScrollMode="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SubtitleTextBlockStyle}"/>
<TextBlock Style="{StaticResource BodyTextBlockStyle}" TextWrapping="Wrap" Margin="0,8,0,0">
The PointerPoint class provides basic properties for the input pointer associated with a single mouse, pen/stylus, or touch contact. This scenario demonstrates how to retrieve a PointerPoint object in response to an input event, determine what type of input it is (mouse, pen, or touch), and retrieve properties present for all input types and those specific to its type.
</TextBlock>
</StackPanel>
</ScrollViewer>
<TextBlock Grid.Row="1" Text="Touch or click the screen to see information about the current pointer(s)" TextWrapping="Wrap" Padding="0,12,0,0"/>
<Canvas Grid.Row="2" x:Name="mainCanvas" Height="Auto" Margin="12,10,12,12" Background="Transparent"/>
</Grid>
</Page>
Loading