Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Canvas.GetLeft() always receive NaN value
    text
    copied!<p>I'm trying to getLeft of a control in WPF. But I always received the NaN value instead of double value. Here is what I'm trying:</p> <p>XAML:</p> <pre><code>&lt;Canvas Canvas.Left="230" Name="cnvSaver"&gt; &lt;Border Focusable="False" BorderBrush="#7FBFA379" BorderThickness="0 1" Width="460" Height="460"&gt; &lt;Canvas Background="#3FFFFFFF" AllowDrop="True" Name="cnvViewerLower" Drop="cnvViewerLower_Drop" Height="460" Width="460"&gt; &lt;/Canvas&gt; &lt;/Border&gt; &lt;Border Focusable="False" Name="borUpper" BorderBrush="#7FBFA379" BorderThickness="1 0"&gt; &lt;Border.RenderTransform&gt; &lt;TranslateTransform x:Name="borUpperTranslate" X="0"/&gt; &lt;/Border.RenderTransform&gt; &lt;Border.Triggers&gt; &lt;EventTrigger RoutedEvent="RadioButton.Checked"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard Name="stbUpperTranslate" Storyboard.TargetName="borUpperTranslate" Storyboard.TargetProperty="X"&gt; &lt;DoubleAnimation RepeatBehavior="Forever" Name="dbaUpperTranslate" From="230" To="0" Duration="0:0:3" AutoReverse="True"/&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;/Border.Triggers&gt; &lt;Canvas Background="#3FEEDBB3" Drop="cnvViewerUpper_Drop" MouseLeftButtonDown="cnvViewerUpper_MouseLeftButtonDown" MouseMove="cnvViewerUpper_MouseMove" MouseLeftButtonUp="cnvViewerUpper_MouseLeftButtonUp" AllowDrop="True" Width="460" Height="460" Name="cnvViewerUpper"&gt;&lt;/Canvas&gt; &lt;/Border&gt; &lt;/Canvas&gt; </code></pre> <p>Code behind C#:</p> <pre><code>Point p = e.GetPosition(cnvSaver); if (x &gt; p.X) { // Move to Left Border br = cnvViewerUpper.Parent as Border; double left = Canvas.GetLeft(br) - Math.Abs(p.X - x); if(left &gt; 0){ Canvas.SetLeft(br, left); } MessageBox.Show("move to left"); } else if (x == p.X) { MessageBox.Show("standing"); } else { // Move to Right double left = Canvas.GetLeft(borUpper); if (left &gt; 0) { Canvas.SetLeft(borUpper, left); } MessageBox.Show("move to right"); } </code></pre> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload