Solved

WPF C# application to Visual Basic

Posted on 2008-10-23
7
372 Views
Last Modified: 2013-11-26
Hi to all,

I am working with the following application on codeproject:
http://www.codeproject.com/KB/WPF/MarsaX.aspx

This is a great post and application. The bad thing for me is that it is in C#. I am a visual basic programmer and was wondering if someone can translate the code below to VB for me. The online tools available is not of any help and I really don't want to go and learn C# to be able to use this application.

I am trying to accomplish the same kind of look, but with all the items in my database. These items have a picture name and I want to display them the same way.

If I can't translate the application, how would I go about in getting the same look and feel to a WPF Visual Basic type application.

Thanks
private ModelUIElement3D CreateModel(string imageUri, int row, int col)

        {

            //Get a VisualBrush for the Url

            VisualBrush vBrush = GetVisualBrush(imageUri);
 

            //Create the model

            ModelUIElement3D model3D = new ModelUIElement3D

            {

                Model = new GeometryModel3D

                {

                    Geometry = new MeshGeometry3D

                    {

                        TriangleIndices = new Int32Collection(

                            new int[] { 0, 1, 2, 2, 3, 0 }),

                        TextureCoordinates = new PointCollection(

                            new Point[] 

                            { 

                                new Point(0, 1), 

                                new Point(1, 1), 

                                new Point(1, 0), 

                                new Point(0, 0) 

                            }),

                        Positions = new Point3DCollection(

                            new Point3D[] 

                            { 

                                new Point3D(-0.5, -0.5, 0), 

                                new Point3D(0.5, -0.5, 0), 

                                new Point3D(0.5, 0.5, 0), 

                                new Point3D(-0.5, 0.5, 0) 

                            })

                    },

                    Material = new DiffuseMaterial

                    {

                        Brush = vBrush

                    },

                    BackMaterial = new DiffuseMaterial

                    {

                        Brush = Brushes.Black

                    },

                    Transform = CreateGroup(row, col)

                }

            };

            //hook up mouse events, and add to lookup and return the ModelUIElement3D

            model3D.MouseEnter += ModelUIElement3D_MouseEnter;

            model3D.MouseDown += model3D_MouseDown;

            modelToImageLookUp.Add(model3D, imageUri);

            return model3D;

        }

Open in new window

0
Comment
Question by:ALawrence007
  • 3
  • 3
7 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22784896
use this tool to convert C# code to vb.net

http://www.developerfusion.com/tools/convert/csharp-to-vb/
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22784901
find yr converted code
Private Function CreateModel(imageUri As String, row As Integer, col As Integer) As ModelUIElement3D 

    'Get a VisualBrush for the Url 

    Dim vBrush As VisualBrush = GetVisualBrush(imageUri) 

    

    'Create the model 

    Dim model3D As New ModelUIElement3D() 

    'hook up mouse events, and add to lookup and return the ModelUIElement3D 

    model3D.MouseEnter += ModelUIElement3D_MouseEnter 

    model3D.MouseDown += model3D_MouseDown 

    modelToImageLookUp.Add(model3D, imageUri) 

    Return model3D 

End Function 

Open in new window

0
 

Author Comment

by:ALawrence007
ID: 22784938
That is the tool I have been using, but it skips the code below and I can't get the application to work.



{

                Model = new GeometryModel3D

                {

                    Geometry = new MeshGeometry3D

                    {

                        TriangleIndices = new Int32Collection(

                            new int[] { 0, 1, 2, 2, 3, 0 }),

                        TextureCoordinates = new PointCollection(

                            new Point[]

                            {

                                new Point(0, 1),

                                new Point(1, 1),

                                new Point(1, 0),

                                new Point(0, 0)

                            }),

                        Positions = new Point3DCollection(

                            new Point3D[]

                            {

                                new Point3D(-0.5, -0.5, 0),

                                new Point3D(0.5, -0.5, 0),

                                new Point3D(0.5, 0.5, 0),

                                new Point3D(-0.5, 0.5, 0)

                            })

                    },

                    Material = new DiffuseMaterial

                    {

                        Brush = vBrush

                    },

                    BackMaterial = new DiffuseMaterial

                    {

                        Brush = Brushes.Black

                    },

                    Transform = CreateGroup(row, col)

                }

            };

Open in new window

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22784999
check this
'Error: Converting Properties 
 

Private Function CreateModel(ByVal imageUri As String, ByVal row As Integer, ByVal col As Integer) As ModelUIElement3D

            'Get a VisualBrush for the Url

            Dim vBrush As VisualBrush =  GetVisualBrush(imageUri) 

 

            'Create the model

            ModelUIElement3D model3D = New ModelUIElement3D

            {

                Model = New GeomeTryModel3D

                {

                    GeomeTry = New MeshGeomeTry3D

                    {

                        TriangleIndices = New Int32Collection(

                            New Integer() 

                            {

                            	 0, 1, 2, 2, 3, 0 

                            }

),

                        TextureCoordinates = New PointCollection(

                            New Point() 

                            { 

                                New Point(0, 1), 

                                New Point(1, 1), 

                                New Point(1, 0), 

                                New Point(0, 0) 

                            }

),

                        Positions = New Point3DCollection(

                            New Point3D() 

                            { 

                                New Point3D(-0.5, -0.5, 0), 

                                New Point3D(0.5, -0.5, 0), 

                                New Point3D(0.5, 0.5, 0), 

                                New Point3D(-0.5, 0.5, 0) 

                            }

)

                    }

,

                    Material = New DiffuseMaterial

                    {

                        Brush = vBrush

                    }

,

                    BackMaterial = New DiffuseMaterial

                    {

                        Brush = Brushes.Black

                    }

,

                    Transform = CreateGroup(row, col)

                }

            }
 

            'hook up mouse events, and add to lookup and return the ModelUIElement3D

            model3D.MouseEnter += ModelUIElement3D_MouseEnter

            model3D.MouseDown += model3D_MouseDown

            modelToImageLookUp.Add(model3D, imageUri)

            Return model3D

End Function

Open in new window

0
 

Author Comment

by:ALawrence007
ID: 22787311
Nope, still gives me errors... It looks like we just added the C# part to the VB and not translated it.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 22788348
*** I don't work with WPF ****

Soooo....there may some new fancy syntax shortcuts that I don't know yet...   =\

Does this work?
    Private Function CreateModel(ByVal imageUri As String, ByVal row As Integer, ByVal col As Integer) As ModelUIElement3D

        Dim geometry As New MeshGeometry3D

        geometry.TriangleIndices = New Int32Collection(New Integer() {0, 1, 2, 2, 3, 0})

        geometry.TextureCoordinates = New PointCollection( _

            New Point() { _

                New Point(0, 1), _

                New Point(1, 1), _

                New Point(1, 0), _

                New Point(0, 0) _

            })

        geometry.Positions = New Point3DCollection( _

            New Point3D() { _

                New Point3D(-0.5, -0.5, 0), _

                New Point3D(0.5, -0.5, 0), _

                New Point3D(0.5, 0.5, 0), _

                New Point3D(-0.5, 0.5, 0) _

            })
 

        Dim model As New GeometryModel3D

        model.Geometry = geometry

        model.Material = New DiffuseMaterial(GetVisualBrush(imageUri))

        model.BackMaterial = New DiffuseMaterial(Brushes.Black)

        model.Transform = CreateGroup(row, col)
 

        Dim model3D As New ModelUIElement3D()

        model3D.Model = model

        AddHandler model3D.MouseEnter, AddressOf (ModelUIElement3D_MouseEnter)

        AddHandler model3D.MouseDown, AddressOf model3D_MouseDown

        modelToImageLookUp.Add(model3D, imageUri)

        Return model3D

    End Function

Open in new window

0
 

Author Comment

by:ALawrence007
ID: 22788587
Thank you SO much Idle_Mind!

That did the trick!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Service with UDP 2 28
String manipulation 15 49
Why don't I see this table in EDMX file? 2 20
C# TextBox 11 12
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now