[UWP] [C#]尝试在UWP中每次在屏幕上写入和删除文本 [英] [UWP][C#]Trying to write and erase the text every time on my screen in UWP
问题描述
我正在尝试编写和删除文本每次都在我的屏幕上uwp,但它只能在第一次工作之后,我既不能在屏幕上写,也不能
i可以擦除我写的东西。而且颜色选择器在选择颜色后没有消失
Xaml代码
<Page xmlns:my="using:Coding4Fun.Toolkit.Controls"
x:Class="ABCD_kids.WorkBook"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ABCD_kids"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="ms-appx:///ABCD/Workbook_bg.png"/>
</Grid.Background>
<!--<InkCanvas Name="ink"/>-->
<RelativePanel x:Name="HomePanel" Grid.Row="0" Canvas.ZIndex="1">
<Image x:Name="Home" Source="ABCD/Home.png"
RelativePanel.AlignLeftWithPanel="True"
Margin="10,10,0,0" Tapped="HomePage"
Width="40" Height="40"/>
<Rectangle x:Name="Bg_Rect" Fill="White"
Width="310" Height="80"
RelativePanel.AlignHorizontalCenterWithPanel="True"
Margin="0,52,0,0"/>
<Image x:Name="Alph_cap" Source="ABCD/Cap_alpha/Cap_0.png"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below="Home"
Margin="60,-9,0,0"
Width="100" Height="100"/>
<TextBlock x:Name="CapAlphaName"
Text="Ant"
FontFamily="Font/VAG Round.TTF#VAG Round"
RelativePanel.AlignTopWithPanel="True"
RelativePanel.RightOf="Alph_cap"
Foreground="BlueViolet"
Margin="10,70,0,0" FontSize="39" FontStretch="UltraCondensed">
</TextBlock>
<Grid x:Name="Bg_BigRect" Background="White"
Width="310" Height="440"
RelativePanel.Below="Bg_Rect"
Margin="24,10,0,0">
<Image x:Name="Trans_Tex" Source="WorkBook/T0.png"
Margin="-10,0,0,20"
Width="310" Height="370"/>
<InkCanvas x:Name="ink"/>
</Grid>
<Image x:Name="WPrev" Source="ABCD/Previous.png"
RelativePanel.AlignBottomWithPanel="True"
Margin="49,0,0,10" Tapped="WPrevTap"
Width="40" Height="40"/>
<my:ColorPicker x:Name="W_Paints"
Margin="216,203,-6,0" Height="374"
Width="374" VerticalAlignment="Top"
HorizontalAlignment="Left"
Visibility="Collapsed"
ColorChanged="CPtest_ColorChanged"/>
<!--<controls:ColorPicker x:Name="W_Paints"
Margin="216,203,-6,0" Height="40"
Width="40" VerticalAlignment="Top"
HorizontalAlignment="Left"></controls:ColorPicker>-->
<Image x:Name="W_Paint" Source="ABCD/W_Paint.png"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.RightOf="WPrev"
Margin="17,0,0,10" Tapped="W_Paintt"
Width="40" Height="40">
</Image>
<Image x:Name="W_Clear" Source="ABCD/Clear_all.png"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.RightOf="W_Paint" Tapped="W_ClearTap"
Margin="17,0,0,10"
Width="40" Height="40"/>
<Image x:Name="W_Mactive" Source="ABCD/Music_active.png"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.RightOf="W_Clear"
Margin="17,0,0,10" Tapped="W_MactiveTap"
Width="40" Height="40"/>
<Image x:Name="W_Fwd" Source="ABCD/Forward.png"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.RightOf="W_Mactive"
Margin="17,0,0,10" Tapped="W_FwdTap"
Width="40" Height="40"/>
</RelativePanel>
<MediaElement x:Name="mediaWorkbook" Source="/Video/workbook.mp3" Volume="0.4" />
</Grid>
</Page>
c#code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.Input.Inking;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace ABCD_kids
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class WorkBook : Page
{
public WorkBook()
{
this.InitializeComponent();
ink.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch;
// Set initial ink stroke attributes.
InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
drawingAttributes.Color = Windows.UI.Colors.Black;
drawingAttributes.IgnorePressure = false;
drawingAttributes.FitToCurve = true;
ink.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
}
string[] CapsAlpha = new string[] { "Ant", "ant", "Bear", "bear", "Cat", "cat", "Dog", "dog", "Elephant", "elephant", "Frog", "frog", "Giraffe", "giraffe", "Hippo", "hippo", "Ice-Cream", "ice-cream", "Jellyfish", "jellyfish", "Kite", "kite", "Lion", "lion", "Mouse", "mouse", "Nest", "nest", "Owl", "owl",
"Parrot", "parrot", "Queen", "queen", "Rabbit", "rabbit", "Sheep", "sheep", "Toy", "toy", "Umbrella", "umbrella", "Vulture", "vulture", "Watch", "watch", "X-ray", "x-ray", "Yak", "yak", "Zebra", "zebra" };
int currentIndex = 0;
private void WPrevTap(object sender, TappedRoutedEventArgs e)
{
currentIndex--;
if (currentIndex < 0)
{
currentIndex = 0;
return;
}
Trans_Tex.Source = new BitmapImage(new Uri("ms-appx:///WorkBook/T" + currentIndex + ".png"));
Alph_cap.Source = new BitmapImage(new Uri("ms-appx:///ABCD/MixCapSmall/CS" + currentIndex + ".png"));
CapAlphaName.Text = CapsAlpha[currentIndex];
//var speechText = this.CapAlphaName.Text;
}
private void W_FwdTap(object sender, TappedRoutedEventArgs e)
{
currentIndex++;
if (currentIndex > 51)
{
currentIndex = 25;
return;
}
Trans_Tex.Source = new BitmapImage(new Uri("ms-appx:///WorkBook/T" + currentIndex + ".png"));
Alph_cap.Source = new BitmapImage(new Uri("ms-appx:///ABCD/MixCapSmall/CS" + currentIndex + ".png"));
CapAlphaName.Text = CapsAlpha[currentIndex];
}
private void W_MactiveTap(object sender, TappedRoutedEventArgs e)
{
if ((W_Mactive.Source as BitmapImage).UriSource == new Uri("ms-appx:///ABCD/Music_active.png", UriKind.Absolute))
{
W_Mactive.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Music_mute.png"));
mediaWorkbook.Stop();
}
else
{
W_Mactive.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Music_active.png"));
mediaWorkbook.Play();
}
}
private void W_Paintt(object sender, TappedRoutedEventArgs e)
{
W_Paints.Visibility = Visibility;
}
private void CPtest_ColorChanged(object sender, Windows.UI.Color color)
{
ink.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch;
// Set initial ink stroke attributes.
InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
drawingAttributes.Color = color;
drawingAttributes.IgnorePressure = false;
drawingAttributes.FitToCurve = true;
ink.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
//Bg_BigRect.Background = new SolidColorBrush(color);
}
private void W_ClearTap(object sender, TappedRoutedEventArgs e)
{
this.ink.InkPresenter.InputProcessingConfiguration.Mode = InkInputProcessingMode.Erasing;
//ink.InkPresenter.Strokes.Clear();
//Windows.UI.Input.Inking.InkInputProcessingMode.Erasing;
//this.ink.Strokes.Remove();
}
private void HomePage(object sender, TappedRoutedEventArgs e)
{
this.Frame.Navigate(typeof(MainPage));
}
}
}
参考图片:
推荐答案
您好pariwesh,
Hi pariwesh,
>> 我每次都在尝试编写和删除文本我的屏幕在uwp,但它只能在第一次工作之后,我不能在屏幕上写
,也不能删除我写的
>>I'm trying to write and erase the text every time on my screen in uwp but it works only for the first time after that neither i can write on screen and neither i can erase what i have written
第一次 InkPresenter.Inp utProcessingConfiguration.Mode
是 InkInputProcessingMode.Inking ,因此您可以在屏幕上书写,然后点按
W_Clear 图片并触发了 W_ClearTap 事件,您已将&strong; InkInputProcessingMode
更改为 this.ink.InkPresenter.InputProcessingConfiguration.Mode = InkInputProcessingMode.Erasing ,以这种方式
你可以擦除。如果您想再次写入,则应将
InkInputProcessingMode 更改为着墨 或无。有关详细信息,您可以参考
InkInputProcessingMode 。
At the first time InkPresenter.InputProcessingConfiguration.Mode is InkInputProcessingMode.Inking, so you can write on the screen, after that when you tapped the W_Clear image and triggered the W_ClearTap event, you have changed the InkInputProcessingMode to this.ink.InkPresenter.InputProcessingConfiguration.Mode = InkInputProcessingMode.Erasing, in this way you can just erase. If you want to write again, you should change the InkInputProcessingMode to Inking or none. For details, you can refer to the InkInputProcessingMode.
>> 选择颜色后颜色选择器也不会消失
在 W_Paint 图像中 W_Paintt 分享事件处理程序,您有代码
W_Paints.Visibility = Visibility,您可以将Visibility属性设置为
W_Paints.Visibility选择颜色后,= Visibility.Collapsed 。
In your W_Paint image’s W_Paintt tapped event handler, you have the code W_Paints.Visibility = Visibility, you can set the Visibility property to W_Paints.Visibility = Visibility.Collapsed after you have selected a color.
这篇关于[UWP] [C#]尝试在UWP中每次在屏幕上写入和删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!