1、scrollview支持触摸滚动
scrollview可以设置panningmode=true实现
2、64位软件读取注册表信息出错
在c#中读取注册表可以通过RegistryKey实现。但是windows注册表对64位和32位做了区分。可以通过下面的代码实现同一个路径对64程序的支持
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"))
{
// key now points to the 64-bit key
}
3、wpf的鼠标整件
在wpf中为了支持触摸添加了touch事件。微软估计是为了向下兼容在触发了touch事件后也会触发mouse事件。所以如果想只支持触摸可以只实现touch事件,如果要触摸鼠标都支持只需要写mouse事件即可
4、StoryBoard动画问题
wpf 使用StoryBoard给控件添加动画。如果直接使用Begin整体开始动画会导致我自己的控件被StoryBoard占用。我的改动不能成功生效。需要对每个控件单独设置Begin,并设置Bool为true。在动画结束后Close相关动画下次就可以改动之前的动画
5、wpf 中动态修改图片内容
在wpf中如果使用source去加载一张图片如果要去删除那张图片会提示文件被占用可以通过StreamSource读取文件流。要删除文件时关闭文件流即可
BitmapImage image = new BitmapImage();
m_ImageStream = new FileStream(strImagePath, FileMode.Open);
image.BeginInit();
image.StreamSource = m_ImageStream;
image.EndInit();
imageEditImage.Source = image;
if (m_ImageStream != null)
{
m_ImageStream.Close();
m_ImageStream.Dispose();
}
if (System.IO.File.Exists(strImagePath))
{
System.IO.File.Delete(strImagePath);
}
6、WPF激活窗口
SetForegroundWindow(p.MainWindowHandle);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);