"System.InvalidCastException: Specified cast is not valid.\r\n
currEle.SetValue(Canvas.LeftProperty, xpos1);
at Noesis.DependencyObject+<>c.<CreateSetFunctions>b__24_1 (System.IntPtr cPtr, System.IntPtr dp, System.Object value) [0x0000e] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Proxies\DependencyObjectExtend.cs:428
at Noesis.DependencyObject.SetValue (Noesis.DependencyProperty dp, System.Object value) [0x0008a] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Proxies\DependencyObjectExtend.cs:57
at UnityApp1.UnityApp1MainView.Btn_MouseMove (System.Object sender, Noesis.MouseEventArgs e) [0x000c2] in G:\english\wpftest\Assets\Scenes\UnityApp1MainView.xaml.cs:61
at Noesis.MouseEventArgs.InvokeHandler (System.Delegate handler, System.IntPtr sender, System.IntPtr args) [0x00011] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Proxies\MouseEventArgs.cs:50
at Noesis.EventManager.InvokeHandler (System.IntPtr routedEventPtr, System.Delegate handler, System.IntPtr sender, System.IntPtr args) [0x00026] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Core\Events.cs:578
at Noesis.EventHandlerStore.RaiseRoutedEvent (System.IntPtr cPtrType, System.IntPtr cPtr, System.IntPtr routedEvent, System.IntPtr sender, System.IntPtr e) [0x00084] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Core\Events.cs:267
at Noesis.DependencyObject+<>c.<CreateSetFunctions>b__24_1 (System.IntPtr cPtr, System.IntPtr dp, System.Object value) [0x0000e] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Proxies\DependencyObjectExtend.cs:428
at Noesis.DependencyObject.SetValue (Noesis.DependencyProperty dp, System.Object value) [0x0008a] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Proxies\DependencyObjectExtend.cs:57
at UnityApp1.UnityApp1MainView.Btn_MouseMove (System.Object sender, Noesis.MouseEventArgs e) [0x000c2] in G:\english\wpftest\Assets\Scenes\UnityApp1MainView.xaml.cs:61
at Noesis.MouseEventArgs.InvokeHandler (System.Delegate handler, System.IntPtr sender, System.IntPtr args) [0x00011] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Proxies\MouseEventArgs.cs:50
at Noesis.EventManager.InvokeHandler (System.IntPtr routedEventPtr, System.Delegate handler, System.IntPtr sender, System.IntPtr args) [0x00026] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Core\Events.cs:578
at Noesis.EventHandlerStore.RaiseRoutedEvent (System.IntPtr cPtrType, System.IntPtr cPtr, System.IntPtr routedEvent, System.IntPtr sender, System.IntPtr e) [0x00084] in G:\english\plus\NoesisGUI-Unity-3.1.4-Indie\Runtime\API\Core\Events.cs:267
Code: Select all
private void Btn_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && isMove)
{
FrameworkElement currEle = sender as FrameworkElement;
var e1 = e.GetPosition(null).X;
var e2 = e.GetPosition(null).Y;
var c1 = currEle.GetValue(Canvas.LeftProperty);
var c2 = currEle.GetValue(Canvas.TopProperty);
float f1 =0;
float f2 =0 ;
float.TryParse(c1.ToString(), out f1);
float.TryParse(c2.ToString(), out f2);
double xPos = e1 - pos.X + f1;
double yPos = e2 - pos.Y + f2;
object xpos1 = xPos;
object ypos1 = yPos;
currEle.SetValue(Canvas.LeftProperty, xpos1);
currEle.SetValue(Canvas.TopProperty, ypos1);
pos = e.GetPosition(null);
}
}-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: "System.InvalidCastException: Specified cast is not valid.\r\n
Canvas attached properties are float in Noesis, you are setting them as a double. Please try the following code:
Code: Select all
private void Btn_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && isMove)
{
FrameworkElement currEle = (FrameworkElement)sender;
Point newPos = e.GetPosition(null);
float xPos = newPos.X - pos.X + Canvas.GetLeft(currEle);
float yPos = newPos.Y - pos.Y + Canvas.GetTop(currEle);
Canvas.SetLeft(currEle, xpos1);
Canvas.SetTop(currEle, ypos1);
pos = newPos;
}
}Who is online
Users browsing this forum: Google [Bot] and 13 guests