dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2016
    Posts
    68

    Resolved [RESOLVED] WPF Printing Tutorial Need Assistance on c# Syntax to VB

    Good Morning,

    I am trying to achieve mastery of WPF printing and the Flow Document. I found this tutorial that seems to make sense to me but like most places its written in C#. I just need a bit of help with the vb syntax conversion

    http://www.nbdtech.com/Blog/archive/...-document.aspx

    So on that link there is a section where I am trying to shoehorn the page object I made into my fixeddocument object I made. To do this, this dude wants to use an "Ichild"interface. Here is the code
    PageContent page1Content = new PageContent();
    ((IAddChild)page1Content).AddChild(page1); <-------How do I write the syntax for this/ "What's it doing?! Precious?"
    document.Pages.Add(page1Content);

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: WPF Printing Tutorial Need Assistance on c# Syntax to VB

    That is a C# "explicit cast", the VB equivalent is CType() or DirectCast().

    What is happening on that line is you have a variable 'page1Content' that is of type PageContent. You want to call its AddChild() method. But, for whatever reason, that method is (maybe) not exposed by PageContent. I say "maybe" because there are two possibilities:
    1. The writer was sloppy and the cast is not required.
    2. The method is an "explicit implementation" of the interface method.


    In case (1), it's just sloppiness and you don't really need it. In case (2), it's a feature of C#. The developer might decide they don't want that method appearing as an "obvious" Intellisense choice. When a method is explicitly implemented in C#, it can only be called by casting a class variable to the interface type.

    Personally I don't like doing it all on one line. If I had to do it in VB .NET, the most illustrative way is:
    Code:
    Dim page1Content As New PageContent()
    Dim page1AsAddChild As IAddChild = CType(page1Content, IAddChild)
    page1AsAddChild.AddChild(page1)
    ...
    But I'm not sure what VB does when it's presented with an explicit interface implementation, so it may not need the cast at all.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2016
    Posts
    68

    Re: WPF Printing Tutorial Need Assistance on c# Syntax to VB

    Quote Originally Posted by Sitten Spynne View Post
    That is a C# "explicit cast", the VB equivalent is CType() or DirectCast().

    What is happening on that line is you have a variable 'page1Content' that is of type PageContent. You want to call its AddChild() method. But, for whatever reason, that method is (maybe) not exposed by PageContent. I say "maybe" because there are two possibilities:
    1. The writer was sloppy and the cast is not required.
    2. The method is an "explicit implementation" of the interface method.


    In case (1), it's just sloppiness and you don't really need it. In case (2), it's a feature of C#. The developer might decide they don't want that method appearing as an "obvious" Intellisense choice. When a method is explicitly implemented in C#, it can only be called by casting a class variable to the interface type.

    Personally I don't like doing it all on one line. If I had to do it in VB .NET, the most illustrative way is:
    Code:
    Dim page1Content As New PageContent()
    Dim page1AsAddChild As IAddChild = CType(page1Content, IAddChild)
    page1AsAddChild.AddChild(page1)
    ...
    But I'm not sure what VB does when it's presented with an explicit interface implementation, so it may not need the cast at all.
    Thanks, that got me through to successfully sending the job to the printer. The Ctype cast was not needed. " Dim page1asaddchild As IAddChild = page1Content " worked perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.