gpt4 book ai didi

c# - 阻止 WPF InkBrush 引起滚动事件

转载 作者:行者123 更新时间:2023-11-30 12:37:55 24 4
gpt4 key购买 nike

应用

我正在开发 EHR 应用程序。我正在处理的页面允许用户使用 InkCanvasInkBrush 在患者的笔记上作画。当用户使用鼠标绘图时,一切都完美无缺。 但是,当他们使用触摸屏绘制滚动条时,也会被操纵。这会导致页面在绘制时滚动。

我尝试过的

到目前为止,我主要使用 e.handled 尝试处理触摸事件,例如 TouchDownTouchUpTouchMove = 真

应用程序代码(抱歉,代码太多!)

ScribblePad.xaml(Border + InkCanvas 代码片段)

<Border Grid.Column="1"
Margin="1,1,8,8"
Background="White"
BorderBrush="Black"
BorderThickness="1"
Cinch:SingleEventCommand.RoutedEventName="MouseDown"
Cinch:SingleEventCommand.TheCommandToRun="{Binding
AddTextCommand}"
RequestBringIntoView="Border_RequestBringIntoView">
<Border.Effect>
<DropShadowEffect />
</Border.Effect>

<InkCanvas x:Name="NewScribbles"
Width="{Binding Parent.PageWidth}"
Height="{Binding Parent.PageHeight}"
DefaultDrawingAttributes="{Binding Parent.SelectedInkBrush}"
EditingMode="{Binding Parent.InkEditMode}"
Strokes="{Binding NewStrokes}">
<Grid>
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Style.Triggers>
<DataTrigger Binding="{Binding Parent.IsTextMode}"
Value="True">
<Setter Property="Cursor"
Value="IBeam" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<ContentPresenter Width="{Binding Parent.PageWidth}"
Height="{Binding Parent.PageHeight}"
Content="{Binding WrappedVisual}" />
<ItemsControl x:Name="PastScribbles"
ItemsSource="{Binding ScribbleData}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding DataContext.PageWidth, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}"
Height="{Binding DataContext.PageHeight, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}"
Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}">
<InkPresenter Strokes="{Binding Strokes}"
Visibility="{Binding InkVisibility}">
<InkPresenter.Effect>
<DropShadowEffect Opacity="{Binding DropShadowOpacity}"
ShadowDepth="2" />
</InkPresenter.Effect>
</InkPresenter>

<ItemsControl Width="{Binding DataContext.PageWidth, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}"
Height="{Binding DataContext.PageHeight, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}"
ItemsSource="{Binding TextData}"
Visibility="{Binding TextVisibility}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Margin="4"
FontSize="{Binding TextData.FontSize}"
FontWeight="{Binding FontWeight}"
Text="{Binding TextData.Text, FallbackValue=This is a placeholder}"
TextWrapping="Wrap"
MaxWidth="{Binding TextData.MaxWidth}">
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding TextData.TextColor, FallbackValue=Black}" />
</TextBlock.Foreground>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Left"
Value="{Binding TextData.LeftPosition}" />
<Setter Property="Canvas.Top"
Value="{Binding TextData.TopPosition}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.Effect>
<DropShadowEffect Opacity="{Binding DropShadowOpacity}"
ShadowDepth="2" />
</ItemsControl.Effect>
</ItemsControl>

</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</InkCanvas>
</Border>

ScribblePad.cs

  /// <summary>
/// Interaction logic for ScribblePadUC.xaml
/// </summary>
public partial class ScribblePadUC : UserControl
{
/// <summary>
/// Initializes a new instance of the <see cref="ScribblePadUC"/> class.
/// </summary>
public ScribblePadUC()
{
this.InitializeComponent();
}

/// <summary>
/// Handles the RequestBringIntoView event of the Border control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.RequestBringIntoViewEventArgs"/> instance containing the event data.</param>
private void Border_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
// Don't want auto-scrolling when trying to scribble... causes annoying vertical line
e.Handled = true;
}

/// <summary>
/// Handles the Loaded event of the TextBox control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
private void TextBox_Loaded(object sender, RoutedEventArgs e)
{
((TextBox)sender).Focus();
}

/// <summary>
/// Event handler for the PreviewKeyDown event
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The event arguments</param>
private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
bool openAddendem = false;

if (Keyboard.IsKeyDown(Key.A) && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
{
openAddendem = true;
}

if (openAddendem == true)
{
ScribblePadVM vm = this.DataContext as ScribblePadVM;

if (vm != null)
{
if (vm.AddendumWidth.Value == 0)
{
vm.AddendumOpenCloseCommand.Execute(null);
}

vm.AddAddendumCommand.Execute(true);

e.Handled = true;
}
}
}

/// <summary>
/// Event handler for the loaded event
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The event arguments</param>
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Window window = this.TryFindVisualParent<Window>();

if (window != null && window is HealthRecord.HealthRecordWindow)
{
window.PreviewKeyDown += (s, args) =>
{
this.UserControl_PreviewKeyDown(s, args);
};
}
}
}
}

我有意将 ViewModel.cs 排除在外,因为它很可能与此问题无关。

我想要发生的事情

当我使用触摸屏时,如果我试图在 Canvas 上绘图,则滚动条不受控制。

感谢阅读。

最佳答案

PreviewTouchDown允许您在触摸事件冒泡到相应的 UI 元素之前对其进行处理。 PreviewMouseDown也是如此.

(给出官方答案以便问题可以标记为已解决)

关于c# - 阻止 WPF InkBrush 引起滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57697547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com