문제

I need to figure out how to change the UserControl's Width and Height at runtime. I am trying to do this during a mouseMove event. The Width and Height are set to Auto in XAML.

'mouseDown event
mouseVerticalPosition = e.GetPosition(Nothing).Y
mouseHorizontalPosition = e.GetPosition(Nothing).X

'mouseMove event
Dim deltaV As Double = e.GetPosition(Nothing).Y - mouseVerticalPosition
Dim deltaH As Double = e.GetPosition(Nothing).X - mouseHorizontalPosition

Me.Width = Me.Width + deltaH
UpdateLayout() 'does not work

This code is inside of the UserControl not the Page where the UserControl lives - if that helps.

Consider the container and it's properties - auto and stretch are used here:

<Grid x:Name="LayoutRoot" Background="Transparent" >
 <Canvas Name="cnv" Margin="18">
      <Rectangle Name="Rect" Margin="0" />
 </Canvas>
</Grid>
도움이 되었습니까?

해결책

The actual numeric value of an Auto setting on Width or Height is Double.NaN. When you add anything to that initial NaN value the result will always still be NaN. You can either use ActualWidth/ActualHeight instead as the number to add to or try adding a Double.IsNaN check before you set the value and if true just use ActualWidth/ActualHeight.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top