【发布时间】:2021-07-08 12:59:58
【问题描述】:
我正在将使用 {Binding} 标记扩展的代码移植到更现代的 {x:Bind} 并在构建我的项目时遇到以下错误:
Cannot directly bind type 'System.Double' to 'System.Single'. Use a cast, converter or function binding to change the type
我的代码如下:
<Grid>
<TextBlock Text="Rotation"
Rotation="{x:Bind slider.Value}"
x:DefaultBindMode="OneWay"
FontWeight="Bold"
FontSize="36"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<Slider x:Name="slider"
Maximum="360"
VerticalAlignment="Stretch" />
</Grid>
我可以看到Slider.Value 被定义为Double,其中TextBlock.Rotation 是一个浮点数。将slider.Value 转换为Single 的正确方法是什么?
我尝试像这样{x:Bind (x:Single)slider.Value} 进行强制转换,但构建失败并出现错误:
Invalid binding path '(x:Single)slider.Value' : Type 'x:Single' not found.
【问题讨论】: