c# - uwp xaml 中是否支持浮点类型?
问题描述
我正在将 C# WPF 组件转换为 UWP,它包含具有浮点类型属性的类。
尝试在 xaml 中设置值时,Visual Studio xaml 编辑器抱怨:“无法将 'System.Double' 类型的对象转换为 'System.Single' 类型。运行时:无法转换为 Windows.Foundation.Single。
双打工作正常。
UWP ScrollViewer 具有例如 MinZoomFactor 属性,它是浮动的,它不会产生任何问题。
UIElement 也有 Rotation 属性,它是浮动的。
所以有人会猜测浮动应该是可能的,但如果有的话,怎么做?
阅读一些文档,这表明不支持浮动,这对于 ScrollViewer 和 UIElement 来说有点奇怪。
https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/xaml-cust-ctrl
这是来自测试项目如何定义浮动属性。
public static DependencyProperty ValueProperty =
DependencyProperty.Register(
"Value",
typeof(float),
typeof(FloatContainer),
new PropertyMetadata(0.0f, new PropertyChangedCallback(ValueChanged)));
public float Value
{
get { return (float)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
解决方案
推荐阅读
- javascript - 在 Node MVC 中传递 req.params
- c# - Percolator 分析服务在 mdx 查询(LINQ to mdx)中的多个 where 条件
- php - 带有会话、登录和面板的 PHP 重定向 php
- python - 在 pandas 中,如何选择 datetime64 格式的年份,同时选择空白行?
- javascript - d3.js 树图图像下载未显示树的整个图像。随着图表大小的增加,图像的某些部分不可见
- javascript - 禁用浏览器后退按钮时启用前进按钮
- powershell - 每行的powershell export-csv总和列
- swift - 最初只为 iPad 设置后,无法获取图标资产注册以显示 iPhone
- python - 在python中读取配置文件
- mongodb - 使用匹配、查找、展开后需要在输出中形成 $group 字段