我们开始在Windows 8中创建WPF触摸应用程序,最近迁移到Windows 10.我们实现的一个功能是在TextBox获得焦点时打开Windows键盘.在Windows 8中,可以通过设置注册表设置EdgeTargetDockedState并启动TabTip过程将键盘停靠在底部:
string path = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
var info = new ProcessStartInfo(path);
info.WindowStyle = ProcessWindowStyle.Maximized;
var p = new Process();
p.StartInfo = info;
p.Start();
Run Code Online (Sandbox Code Playgroud)
然而,Windows 10键盘似乎没有Windows 8中的停靠行为.键盘现在覆盖任何最大化的窗口,隐藏任何应用程序的底部.仅调整未最大化的窗口以适应剩余空间.
我检查了以下链接,但没有找到解决方案:
Windows 10键盘是否可以通过编程方式停靠以获得最大化的窗口?
我遇到了ComboBox最终能够解决的 WPF问题。但问题的原因尚不清楚。
使用时出现的问题ComboBox,其中ItemsSource被引用不同的DataContext比SelectedValue。执行此操作并导航离开时,该SelectedValue属性设置为null。由于某些属性在更改时包含逻辑(当字段 A 更改时,也会更改字段 B),因此某些逻辑执行不正确。
<ComboBox x:Name="Sector"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SectorList}"
SelectedValuePath="Id"
SelectedValue="{Binding SectorId, Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
我发现了几个类似的问题(这可能是最接近的:https : //stackoverflow.com/a/5033924/3357566),但没有一个解决了我的问题。许多修复与加载顺序有关ItemsSource,SelectedValue因此这使我走上了正确的轨道。
我没有DataContext从UserControlthrough RelativeSources中获取 ,而是遍历了 ViewModels 的父级以找到 SectorList,因此 XAML 现在如下所示(注意Root属性):
<ComboBox x:Name="Sector"
ItemsSource="{Binding Root.SectorList}"
SelectedValuePath="Id"
SelectedValue="{Binding SectorId, Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下为什么后一个代码在离开页面时没有清除 SelectedValue 而第一个代码会清除吗?
编辑
澄清 的结构ViewModels:
ComboBoxes仅在 中使用的要填充的列表CustomerEntryViewModel …更新
Gepost door Microsoft op 13/10/2017 om 11:38
感谢您报告此事.我们已经意识到这个问题并且正在将其修复到.NET的未来版本中.还有一个相关问题正在服务修复中发布,这将大大降低遇到此问题的可能性.这将很快得到服务.
问题
我们的WPF应用程序正在使用触摸(没有手写笔)的平板电脑上使用,我们在安装.NET Framework 4.7后遇到问题.使用应用程序一段时间后可能会出现两种情况:应用程序完全冻结,必须重新启动或禁用所有触摸功能Popup或Window元素.两者之间存在很大差异,但我相信原因是一样的.
场景1:完全冻结
指数数组的边界之外.
这是堆栈跟踪:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Windows.Input.StylusWisp.WispLogic.CoalesceAndQueueStylusEvent(RawStylusInputReport inputReport)
at System.Windows.Input.StylusWisp.WispLogic.ProcessSystemEvent(PenContext penContext, Int32 tabletDeviceId, Int32 stylusDeviceId, Int32 timestamp, SystemGesture systemGesture, Int32 gestureX, Int32 gestureY, Int32 buttonState, PresentationSource inputSource)
at System.Windows.Input.PenContext.FireSystemGesture(Int32 stylusPointerId, Int32 timestamp)
at System.Windows.Input.PenThreadWorker.FireEvent(PenContext penContext, Int32 evt, Int32 stylusPointerId, Int32 cPackets, Int32 cbPacket, IntPtr pPackets)
at System.Windows.Input.PenThreadWorker.ThreadProc()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object …Run Code Online (Sandbox Code Playgroud) 我正在使用Linq查询来获取客户及其可选的主要地址(客户可以拥有零个或多个地址).对象层次结构如下:
这是我正在使用的查询:
var qry = from customer cus in GetDBContext(c).customer
join cusadd in GetDBContext(c).customeraddress on new { cus_code = cus.cus_code, main = "1" } equals new { cus_code = cusadd.cus_code, main = cusadd.Main_addr } into grpcusadd
from cusadd in grpcusadd.DefaultIfEmpty()
join add in GetDBContext(c).address on new { addr_code = cusadd.Addr_Code } equals new { addr_code = add.Addr_Code } into grpadd
from add in grpadd.DefaultIfEmpty()
select new { cus, cusadd, add };
var customers = qry.ToList();
Run Code Online (Sandbox Code Playgroud)
当我在数据库上执行它(通过EF)时,它会正确返回值.当我在内存对象的模拟上下文中执行它时,我得到一个NullReferenceException:对象引用未设置为对象的实例. …
我们正在 WPF 中开发触摸应用程序。我们的 ScrollViewers 将属性 PanningMode 设置为 Both 以启用滑动滚动。当在空白区域甚至在 CheckBox 和 ComboBox 控件上滑动时,此功能效果很好。
但是,当在文本框上滑动(将手指短暂地放在文本框上并向上或向下移动)时,ScrollViewer 不会滚动。有没有办法在所有控件上启用滑动滚动并仅将它们集中在点击上?
可以使用以下代码重现此行为:
<Window x:Class="WpfSandbox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<ScrollViewer PanningMode="Both">
<StackPanel>
<TextBox Margin="5"></TextBox>
<TextBox Margin="5"></TextBox>
<TextBox Margin="5"></TextBox>
<TextBox Margin="5"></TextBox>
<TextBox Margin="5"></TextBox>
<TextBox Margin="5"></TextBox>
<TextBox Margin="5"></TextBox>
<TextBox Margin="5"></TextBox>
<CheckBox Margin="5" />
<CheckBox Margin="5" />
<CheckBox Margin="5" />
<CheckBox Margin="5" />
<CheckBox Margin="5" />
<CheckBox Margin="5" />
<CheckBox Margin="5" />
<CheckBox Margin="5" />
<ComboBox Margin="5" />
<ComboBox Margin="5" />
<ComboBox Margin="5" />
<ComboBox Margin="5" />
<ComboBox Margin="5" …Run Code Online (Sandbox Code Playgroud) c# ×5
wpf ×4
touch ×2
.net-4.7 ×1
combobox ×1
linq ×1
mvvm ×1
scrollviewer ×1
windows-10 ×1
xaml ×1