Solved

WPF C# application to Visual Basic

Posted on 2008-10-23
7
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 86

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

690 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