指定的转换无效?解决方案
指定的转换无效?
控件中XAML如下:
其中绑定函数如下:
<Binding ElementName="Arc_Monitor" Path="Percent" Mode="OneWay"></Binding>
这一句中,Percent是自定义的依赖项属性,结果在编译器中就报错“指定的转换无效”,而在其他程序中加载此控件则能正常运行,请问如何解决这所谓的“转换无效”问题?
------解决思路----------------------
Percent 是什么类型的? 在Converter中 加个断点,看value[1] 的值。
控件中XAML如下:
<UserControl x:Name="Arc_Monitor" x:Class="FN_InventoryMonitor.ArcMonitor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FN_InventoryMonitor"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Loaded="Arc_Monitor_Loaded">
<UserControl.Resources>
<local:PointStartOuter x:Key="PointStratOuter"></local:PointStartOuter>
<local:PointEndOuter x:Key="PointEndOuter"></local:PointEndOuter>
<local:PointStartInner x:Key="PonitStratInner"></local:PointStartInner>
</UserControl.Resources>
<Grid>
<Canvas>
<Path Stroke="Blue" Fill="White" >
<Path.Data>
<PathGeometry>
<PathFigure IsClosed="False" StartPoint="{Binding ElementName=Arc_Monitor,Path=ActualWidth,Converter={StaticResource PointStratOuter}}">
<ArcSegment x:Name="Arc_Outer" Size="150,150" SweepDirection="Clockwise" IsLargeArc="False">
<ArcSegment.Point>
<MultiBinding Converter="{StaticResource PointEndOuter}">
<Binding ElementName="Arc_Monitor" Path="ActualWidth" Mode="OneWay"></Binding>
<Binding ElementName="Arc_Monitor" Path="Percent" Mode="OneWay"></Binding>
</MultiBinding>
</ArcSegment.Point>
</ArcSegment>
<!--<LineSegment Point="180,100"></LineSegment>-->
<!--<ArcSegment Point="100,20" Size="80,80" SweepDirection="Counterclockwise" IsLargeArc="False"></ArcSegment>-->
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
</Grid>
</UserControl>
其中绑定函数如下:
public class PointEndOuter : IMultiValueConverter
{
public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
{
double width = (double)value[0];
width /= 2;
double percent = (double)value[1];
Point point = new Point((width + Math.Sin(360 * percent / 100) * width), (width - Math.Cos(360 * percent / 100) * width));
return point;
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
<Binding ElementName="Arc_Monitor" Path="Percent" Mode="OneWay"></Binding>
这一句中,Percent是自定义的依赖项属性,结果在编译器中就报错“指定的转换无效”,而在其他程序中加载此控件则能正常运行,请问如何解决这所谓的“转换无效”问题?
------解决思路----------------------
Percent 是什么类型的? 在Converter中 加个断点,看value[1] 的值。