質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
UWP

UWPは、Universal Windows Platformの略。様々なデバイス向けに提供されているアプリケーションを共通のフレームワーク上で動作可能にする仕組みで、Windows10で導入されました。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

Q&A

解決済

1回答

1364閲覧

UWPアプリで筆圧値を確認したい.

gaki14

総合スコア24

UWP

UWPは、Universal Windows Platformの略。様々なデバイス向けに提供されているアプリケーションを共通のフレームワーク上で動作可能にする仕組みで、Windows10で導入されました。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

0グッド

0クリップ

投稿2019/08/26 07:37

前提・実現したいこと

xaml&C#で筆圧を測定するUWPアプリを作成しようとしています.
■■な機能を実装中に以下のエラーメッセージが発生しました。

発生している問題・エラーメッセージ

ビルドエラーや動作が止まるといったことはないのですが,筆圧値を確認することができません. どのようにすれば値が確認できるか教えていただけると非常にありがたいです. 初心者で分からないことが多いので細かく教えていただけると助かります.

該当のソースコード

MainPagexaml

1<Page 2 x:Class="UWPApp1.MainPage" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:UWPApp1" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 mc:Ignorable="d" 9 Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 10 11 <Grid> 12 <Grid Background="White"> 13 <Button HorizontalAlignment="Left" Margin="50,40,0,0" VerticalAlignment="Top" Width="124" Background="#00838F" Click="Button_Click" Height="40" > 14 <Button.Content> 15 <TextBlock Text="次の画面へ" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,1,0,0" > 16 <TextBlock.Foreground> 17 <SolidColorBrush Color="#E0F7FA"></SolidColorBrush> 18 </TextBlock.Foreground> 19 </TextBlock> 20 </Button.Content> 21 </Button> 22 </Grid> 23 </Grid> 24</Page> 25

MainPagecs

1using System; 2using System.Collections.Generic; 3using System.IO; 4using System.Linq; 5using System.Runtime.InteropServices.WindowsRuntime; 6using Windows.Foundation; 7using Windows.Foundation.Collections; 8using Windows.UI.Core; 9using Windows.UI.Xaml; 10using Windows.UI.Xaml.Controls; 11using Windows.UI.Xaml.Controls.Primitives; 12using Windows.UI.Xaml.Data; 13using Windows.UI.Xaml.Input; 14using Windows.UI.Xaml.Media; 15using Windows.UI.Xaml.Navigation; 16 17// 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください 18 19namespace UWPApp1 20{ 21 /// <summary> 22 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 23 /// </summary> 24 public sealed partial class MainPage : Page 25 { 26 public MainPage() 27 { 28 this.InitializeComponent(); 29 } 30 protected override void OnNavigatedTo(NavigationEventArgs e) 31 { 32 SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = Frame.CanGoBack ? 33 AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; 34 base.OnNavigatedTo(e); 35 } 36 private void Button_Click(object sender, RoutedEventArgs e) 37 { 38 Frame.Navigate(typeof(BlankPage1)); 39 } 40 } 41} 42

BlankPage1xaml

1<Page 2 x:Class="UWPApp1.BlankPage1" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:UWPApp1" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 mc:Ignorable="d" 9 Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 10 11 <Grid> 12 <Grid Background="White"> 13 <Grid.RowDefinitions> 14 <RowDefinition Height="Auto"/> 15 <RowDefinition Height="*"/> 16 </Grid.RowDefinitions> 17 <StackPanel x:Name="HeaderPanel" 18 Orientation="Horizontal" 19 Grid.Row="0"> 20 <TextBlock x:Name="Header" 21 Style="{ThemeResource HeaderTextBlockStyle}" 22 Margin="10,0,0,0" SelectionChanged="Header_SelectionChanged" ><Run Text="描画してください"/><LineBreak/><Run/></TextBlock> 23 <Button x:Name="recognize" 24 Content="Recognize" 25 Margin="50,0,10,0"/> 26 </StackPanel> 27 <Grid x:Name="drawingCanvas" Grid.Row="1" FocusVisualPrimaryBrush="Black"> 28 <Grid.ColumnDefinitions> 29 <ColumnDefinition Width="7*"/> 30 <ColumnDefinition Width="243*"/> 31 </Grid.ColumnDefinitions> 32 <Grid.FocusVisualSecondaryBrush> 33 <AcrylicBrush/> 34 </Grid.FocusVisualSecondaryBrush> 35 36 <!-- The canvas where we render the replacement text and shapes. --> 37 <!-- The canvas for ink input. --> 38 <InkCanvas x:Name="inkCanvas" Grid.ColumnSpan="2" Margin="6,0,-6,0" FocusVisualPrimaryBrush="{x:Null}" FocusVisualSecondaryBrush="{x:Null}" Opacity="0.5" /> 39 40 <!-- The canvas where we render the replacement text and shapes. --> 41 <Canvas x:Name="recognitionCanvas" Grid.ColumnSpan="2" /> 42 <!-- The canvas for ink input. --> 43 44 </Grid> 45 </Grid> 46 <Canvas HorizontalAlignment="Left" VerticalAlignment="Top"> 47 <Border 48 Height="187" Width="189" Canvas.Left="-48" Canvas.Top="-42"> 49 <Canvas> 50 <Ellipse 51 Stroke="#FF044B0A" FocusVisualPrimaryBrush="{x:Null}" FocusVisualSecondaryBrush="{x:Null}" Margin="132,189,-132,-189" 52 Height="187" Width="189" RenderTransformOrigin="0.5,0.5" Visibility="Visible" RequestedTheme="Light" Canvas.Left="99" Canvas.Top="162" UseLayoutRounding="False" d:LayoutRounding="Auto" 53 > 54 <Ellipse.RenderTransform> 55 <CompositeTransform Rotation="-0.481"/> 56 </Ellipse.RenderTransform> 57 </Ellipse> 58 </Canvas> 59 </Border> 60 </Canvas> 61 <Button Content="Button" Margin="118,63,0,0" VerticalAlignment="Top" RenderTransformOrigin="-3.172,0.297" Click="Button_Click"/> 62 <TextBlock HorizontalAlignment="Left" Margin="121,91,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="24"><Run Text="戻るボタン"/><LineBreak/><Run/></TextBlock> 63 </Grid> 64 65</Page> 66 67

BlankPage1cs

1using System; 2using System.Collections.Generic; 3using System.Diagnostics; 4using System.IO; 5using System.Linq; 6using System.Runtime.InteropServices.WindowsRuntime; 7using Windows.Foundation; 8using Windows.Foundation.Collections; 9using Windows.UI.Core; 10using Windows.UI.Input; 11using Windows.UI.Input.Inking; 12using Windows.UI.Xaml; 13using Windows.UI.Xaml.Controls; 14using Windows.UI.Xaml.Controls.Primitives; 15using Windows.UI.Xaml.Data; 16using Windows.UI.Xaml.Input; 17using Windows.UI.Xaml.Media; 18using Windows.UI.Xaml.Navigation; 19 20 21// 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=234238 を参照してください 22 23namespace UWPApp1 24{ 25 /// <summary> 26 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 27 /// </summary> 28 public sealed partial class BlankPage1 : Page 29 { 30 public BlankPage1() 31 { 32 this.InitializeComponent(); 33 // 描画属性を作成する 34 InkDrawingAttributes attributes = new InkDrawingAttributes(); 35 attributes.Color = Windows.UI.Colors.Red; // ペンの色 36 attributes.Size = new Size(5, 2); // ペンのサイズ 37 attributes.IgnorePressure = true; // ペンの圧力を使用するかどうか 38 attributes.FitToCurve = false; 39 40 // インクキャンバスに属性を設定する 41 inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(attributes); 42 // マウスとペンによる描画を許可する 43 inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen; 44 } 45 protected override void OnNavigatedTo(NavigationEventArgs e) 46 { 47 SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = Frame.CanGoBack ? 48 AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; 49 SystemNavigationManager.GetForCurrentView().BackRequested += hogehoge; 50 base.OnNavigatedTo(e); 51 } 52 private void hogehoge(object obj, Windows.UI.Core.BackRequestedEventArgs e) 53 { 54 if (Frame.CanGoBack) 55 { 56 Frame.GoBack(); 57 if (e != null) 58 e.Handled = true; 59 } 60 } 61 private void Button_Click(object sender, RoutedEventArgs e) 62 { 63 hogehoge(sender, null); 64 } 65 private void Grid_PointerMoved(object sender, PointerRoutedEventArgs e) 66 { 67 // 0~1の間で筆圧が取れる 68 var pressure = e.GetCurrentPoint(null).Properties.Pressure; 69 Debug.WriteLine(pressure); 70 71 } 72 73 74 private void Header_SelectionChanged(object sender, RoutedEventArgs e) 75 { 76 77 } 78 } 79} 80

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

XAML側にGrid_PointerMovedハンドラーを呼び出す部分が見当たりませんが、忘れていますかね?

投稿2019/08/26 07:49

takabosoft

総合スコア8356

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

gaki14

2019/08/26 08:01

度々返信ありがとうございます. 忘れているのではなく,知りませんでした…すみません.基本的なことなのでしょうか? ちなみに呼び出し方がわかりません.どのような文をどこに挿入すれば良いのでしょうか?
takabosoft

2019/08/26 08:21

イベントを拾いたいGrid要素の属性として <Grid PointerMoved="Grid_PointerMoved"> のような感じで書けば良いかと思われます。
gaki14

2019/08/26 08:37

出ました!PCでやったためか0.5と表示されました. 丁寧に教えていただきありがとうございました. ずっと止まっていたのでうれしいです. また,教えていただけると助かります!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問