Commit bce25c66 by liulongfei

扩展功能

parent 99bd5ece
......@@ -142,8 +142,10 @@ namespace VIZ.Framework.Common
if (this.PART_ContainerForm == null)
return;
int width = (int)sizeInfo.NewSize.Width;
int height = (int)sizeInfo.NewSize.Height;
var dpi = WPFHelper.GetDpiByGraphics();
int width = (int)(sizeInfo.NewSize.Width * (dpi.X / 96d));
int height = (int)(sizeInfo.NewSize.Height * (dpi.Y / 96d));
// 改变宿主窗口大小
if (!Win32Helper.MoveWindow(this.PART_ContainerForm.Handle, 0, 0, width, height, false))
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VIZ.Framework.Core
{
/// <summary>
/// 数字相加转化器
/// </summary>
public class NumberAddConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int a = 0;
int b = 0;
if (value != null)
{
int.TryParse(value.ToString(), out a);
}
if (parameter != null)
{
int.TryParse(parameter.ToString(), out a);
}
return a + b;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VIZ.Framework.Core
{
/// <summary>
/// 非空字符串到Bool转化
/// </summary>
public class StringNotNull2BoolConverter : IValueConverter
{
/// <summary>
/// 为空时的返回值
/// </summary>
public bool NullResult { get; set; } = false;
/// <summary>
/// 非空时的返回值
/// </summary>
public bool NotNullResult { get; set; } = true;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is string))
return this.NullResult;
string str = value as string;
return string.IsNullOrWhiteSpace(str) ? this.NullResult : this.NotNullResult;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using log4net;
using TDx.SpaceMouse.Navigation3D;
......@@ -18,6 +21,22 @@ namespace VIZ.Framework.Core
public static class WPFHelper
{
/// <summary>
/// DPI值
/// </summary>
public class DPI
{
/// <summary>
/// X DPI值
/// </summary>
public double X { get; set; }
/// <summary>
/// Y DPI值
/// </summary>
public double Y { get; set; }
}
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(WPFHelper));
......@@ -33,6 +52,18 @@ namespace VIZ.Framework.Core
}
/// <summary>
/// 获取DPI
/// </summary>
/// <returns>DPI</returns>
public static DPI GetDpiByGraphics()
{
using (var graphics = Graphics.FromHwnd(IntPtr.Zero))
{
return new DPI { X = graphics.DpiX, Y = graphics.DpiY };
}
}
/// <summary>
/// 绑定视图模型
/// </summary>
/// <param name="view">视图</param>
......
......@@ -100,6 +100,8 @@
<Compile Include="Core\Converter\Enum2EnumDescriptionConverter.cs" />
<Compile Include="Core\Converter\String2ImageSourceConverter.cs" />
<Compile Include="Core\Converter\StringAppendConverter.cs" />
<Compile Include="Core\Converter\NumberAddConverter.cs" />
<Compile Include="Core\Converter\StringNotNull2BoolConverter.cs" />
<Compile Include="Core\Enum\EnumHelper.cs" />
<Compile Include="Core\Enum\EnumModel.cs" />
<Compile Include="Core\Helper\ByteHelper.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment