Click here to Skip to main content
15,915,019 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Resource Dictionary and Data Templates Pin
User 2710091-May-09 8:43
User 2710091-May-09 8:43 
GeneralRe: Resource Dictionary and Data Templates Pin
BlitzPackage1-May-09 8:55
BlitzPackage1-May-09 8:55 
QuestionXBAP keyboard event capture Pin
ita6cgr28-Apr-09 5:34
ita6cgr28-Apr-09 5:34 
Questioninternationalization of silverlight applications Pin
ManjuHanzan28-Apr-09 2:12
ManjuHanzan28-Apr-09 2:12 
AnswerRe: internationalization of silverlight applications Pin
Mark Salsbery28-Apr-09 5:40
Mark Salsbery28-Apr-09 5:40 
QuestionProblem with silverlight Pin
sureshreddy178927-Apr-09 22:29
sureshreddy178927-Apr-09 22:29 
AnswerRe: Problem with silverlight Pin
Mark Salsbery28-Apr-09 5:35
Mark Salsbery28-Apr-09 5:35 
QuestionProblem in silverlight Pin
sureshreddy178927-Apr-09 17:26
sureshreddy178927-Apr-09 17:26 
AnswerRe: Problem in silverlight Pin
VCsamir27-Apr-09 19:16
VCsamir27-Apr-09 19:16 
GeneralRe: Problem in silverlight Pin
sureshreddy178927-Apr-09 21:17
sureshreddy178927-Apr-09 21:17 
QuestionRe: Problem in silverlight Pin
Mark Salsbery28-Apr-09 5:36
Mark Salsbery28-Apr-09 5:36 
QuestionSilverlight to WPF Porting Pin
bdb3886527-Apr-09 12:51
bdb3886527-Apr-09 12:51 
AnswerRe: Silverlight to WPF Porting Pin
Mark Salsbery27-Apr-09 14:07
Mark Salsbery27-Apr-09 14:07 
GeneralRe: Silverlight to WPF Porting Pin
bdb3886528-Apr-09 6:42
bdb3886528-Apr-09 6:42 
GeneralRe: Silverlight to WPF Porting Pin
Mark Salsbery28-Apr-09 8:01
Mark Salsbery28-Apr-09 8:01 
GeneralRe: Silverlight to WPF Porting Pin
bdb3886528-Apr-09 11:10
bdb3886528-Apr-09 11:10 
GeneralRe: Silverlight to WPF Porting Pin
Mark Salsbery28-Apr-09 12:44
Mark Salsbery28-Apr-09 12:44 
GeneralRe: Silverlight to WPF Porting Pin
bdb3886529-Apr-09 6:52
bdb3886529-Apr-09 6:52 
QuestionRe: Silverlight to WPF Porting Pin
Mark Salsbery29-Apr-09 7:21
Mark Salsbery29-Apr-09 7:21 
AnswerRe: Silverlight to WPF Porting Pin
bdb3886529-Apr-09 7:44
bdb3886529-Apr-09 7:44 
GeneralRe: Silverlight to WPF Porting Pin
Mark Salsbery29-Apr-09 8:10
Mark Salsbery29-Apr-09 8:10 
The problem isn't in there.

The ImageSpace3D.addImages() method is where the random calculations are made.

The calculations are based on the Width and Height properties of the control, which
are always NaN unless set somewhere, which they are not.

ActualWidth and ActualHeight are the properties that should be used, and should have been
used in the Silverlight version as well.

ActualWidth and ActualHeight are not set until the control is loaded so you need to call the
initialization code from a "Loaded" event handler (or later) instead of from the constructor.

Here's what you should have to make it work...
<!-- ImageSpace3D.xaml -->

<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
	x:Class="ImageSpace3Dwpf.ImageSpace3D"
	x:Name="UserControl"
	d:DesignWidth="640" d:DesignHeight="480" 
	<code>Loaded="UserControl_Loaded"</code> >

	<Grid x:Name="LayoutRoot"/>
</UserControl>

// ImageSpace3D.xaml.cs


        public ImageSpace3D()
        {
            InitializeComponent();

            <code>// note I removed all the initialization code from here
            //    and placed it in the UserControl_Loaded() method below</code>
        }

		
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // add the holder to the canvas
            _holder.SetValue(Canvas.LeftProperty, <code>ActualWidth</code> / 2);
            _holder.SetValue(Canvas.TopProperty, <code>ActualHeight</code> / 2);
            LayoutRoot.Children.Add(_holder);

            // add all the texts to the stage
            addImages();

            // not enough? create more
            addImages();

            // start the enter frame event
            _timer = new DispatcherTimer();
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / FPS);
            _timer.Tick += new EventHandler(_timer_Tick);
            _timer.Start();
        }

		
        <code>// Here note I changed Width and Height to ActualWidth and ActualHeight</code>
	private void addImages()
        {
            int seed = (int)DateTime.Now.Ticks;

            for (int i = 0; i < IMAGES.Length; i++)
            {
                // create a random object
                seed += (int)DateTime.Now.Ticks;
                Random r = new Random(seed);

                // load the image
                String url = IMAGE_PATH + IMAGES[i];
                Image image = new Image();
                image.Source = new BitmapImage(new Uri(url, UriKind.Relative));

                // randomly assign the position
                Point3D point3D = new Point3D();
                point3D.x = r.NextDouble() * <code>ActualWidth - ActualWidth</code> / 2;
                point3D.y = r.NextDouble() * <code>ActualHeight - ActualHeight</code> / 2;
                point3D.z = r.NextDouble() * SPACE_LENGTH * 2 - SPACE_LENGTH;


                // update the image property
                image.SetValue(Canvas.LeftProperty, point3D.x);
                image.SetValue(Canvas.TopProperty, point3D.y);
                image.MouseLeftButtonDown += new MouseButtonEventHandler(image_MouseLeftButtonDown);
                image.Cursor = Cursors.Hand;


                _imagePoint3Ds.Add(image, point3D);
                _holder.Children.Add(image);
                _images.Add(image);
            }
        }


Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: Silverlight to WPF Porting Pin
bdb3886529-Apr-09 9:10
bdb3886529-Apr-09 9:10 
GeneralRe: Silverlight to WPF Porting Pin
Mark Salsbery29-Apr-09 9:13
Mark Salsbery29-Apr-09 9:13 
GeneralRe: Silverlight to WPF Porting Pin
bdb3886529-Apr-09 9:46
bdb3886529-Apr-09 9:46 
GeneralRe: Silverlight to WPF Porting Pin
Mark Salsbery29-Apr-09 10:39
Mark Salsbery29-Apr-09 10:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.