我有一个WPF应用程序,其中有一个使用墨水画布控件的签名页。我有一个非常随机的问题,某些笔划无法在笔划集合中收集并消失。我知道软件中的“随机”一词是忌讳的,但请相信我的随机性。没有多线程发生。
使用鼠标和触摸输入也会发生此问题。
目前尚不清楚源代码是否会有所帮助,但是无论如何我都会将其放在下面
SignatureForm.cs
public partial class SignatureForm : UserControl
{
public event EventHandler SubmitButtonClick;
private byte[] _signatureBytes;
public byte[] SignatureBytes
{
get
{
_signatureBytes = SignatureHelper.GetStrokeBytes(SignatureCanvas.Strokes, SignatureCanvas);
return _signatureBytes;
}
private set => _signatureBytes = value;
}
private Bitmap _signatureImage;
public Bitmap SignatureImage
{
get
{
_signatureImage = SignatureHelper.GetSignatureImage(SignatureCanvas);
return _signatureImage;
}
private set => _signatureImage = value;
}
public SignatureForm()
{
InitializeComponent();
ClearButton.Visibility = Visibility.Hidden;
PlaceholderText.Visibility = Visibility.Visible;
AcceptButton.Visibility = Visibility.Hidden;
}
private void SubmitButton_TouchUp(object sender, TouchEventArgs e)
{
if (TouchIndicator.IsTouchEnabled)
SubmitButtonClick?.Invoke(sender, e);
}
private void SubmitButton_MouseUp(object sender, MouseButtonEventArgs e)
{
if (!TouchIndicator.IsTouchEnabled)
SubmitButtonClick?.Invoke(sender, e);
}
private void ClearButton_OnMouseUp(object sender, MouseButtonEventArgs e)
{
Clear();
}
private void ClearButton_OnTouchUp(object sender, TouchEventArgs e)
{
Clear();
}
private void Clear()
{
SignatureCanvas.Strokes.Clear();
SubmitHide();
}
private void SignatureCanvas_OnStrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
{
SubmitReveal();
}
private void SignatureCanvas_OnTouchDown(object sender, TouchEventArgs e)
{
SubmitReveal();
}
private void SubmitReveal()
{
ClearButton.Visibility = Visibility.Visible;
PlaceholderText.Visibility = Visibility.Hidden;
AcceptButton.Visibility = Visibility.Visible;
}
private void SubmitHide()
{
ClearButton.Visibility = Visibility.Hidden;
PlaceholderText.Visibility = Visibility.Visible;
AcceptButton.Visibility = Visibility.Hidden;
}
private void SignatureCanvas_OnTouchUp(object sender, TouchEventArgs e)
{
if (SignatureCanvas.Strokes.Count == 0) SubmitHide();
}
}
SignatureForm.cs.xaml
<Grid x:Name="SignatureGrid">
<Grid.RowDefinitions>
<RowDefinition Height=".75*" />
<RowDefinition Height=".25*" />
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderThickness="2" BorderBrush="{DynamicResource DarkBlue}">
<Grid>
<TextBlock x:Name="PlaceholderText" Style="{StaticResource SignHereText}" Text="Sign here with your finger"/>
<InkCanvas x:Name="SignatureCanvas" Style="{StaticResource SignatureCanvas}" StrokeCollected="SignatureCanvas_OnStrokeCollected" TouchDown="SignatureCanvas_OnTouchDown" TouchUp="SignatureCanvas_OnTouchUp" />
</Grid>
</Border>
<Border Grid.Row="0" x:Name="ClearButton" Style="{StaticResource ClearSignatureButton}"
MouseUp="ClearButton_OnMouseUp" TouchUp="ClearButton_OnTouchUp">
<TextBlock x:Name="ButtonText" Text="CLEAR" Style="{StaticResource ClearSignatureText}" />
</Border>
<Border Grid.Row="1" BorderThickness="0" BorderBrush="{DynamicResource Teal}" Margin="0 0 0 0"
MouseUp="SubmitButton_MouseUp" TouchUp="SubmitButton_TouchUp">
<TextBlock x:Name="AcceptButton" Style="{DynamicResource SubmitText}">Tap here to submit</TextBlock>
</Border>
</Grid>
答案 0 :(得分:0)
所以我发现了这个问题,有一个属性EditingMode设置为“ InkAndGesture”,删除该属性后,InkCanvas可以正常工作并收集所有笔画。
<Style x:Key="SignatureCanvas" TargetType="InkCanvas">
<Setter Property="Background" Value="{DynamicResource Transparent}" />
<!--<Setter Property="EditingMode" Value="InkAndGesture"/>-->
<Setter Property="DefaultDrawingAttributes">
<Setter.Value>
<DrawingAttributes Width="10" Height="10"/>
</Setter.Value>
</Setter>
</Style>