11 Replies - 1065 Views - Last Post: 17 August 2012 - 12:49 AM Rate Topic: -----

#1 Adidas 777   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 29-July 12

Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:31 AM

Hi
I need please a simple example where should I write the Interface and where shell shall I implement it.

Please be as much as easy as an example can be.
I want only to take 2 numbers and show them to the screen and implement an Interface.

I have 1 button and 2 text boxes.

Thanks in advance 4 any help !!!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for Mainwindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
    }
}



This post has been edited by tlhIn`toq: 16 August 2012 - 08:35 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Interface "All Pack" with WPF Application

#2 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5105
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:35 AM

This sounds like a homework assignment to me. All the code you have posted is a template, an empty shell.

We have no idea what interface you're talking about, what it's supposed to represent, and what relationship it's supposed to have with your form, which we have no idea what is, as well.

Basically, we have nothing to go on to help you.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:38 AM

Do you really mean you want to implement interface?

Or are you using the word interface in a generic meaning for the GUI or user interface - In other words do you really need an interface class or do you just mean to show the information on your window?

This post has been edited by tlhIn`toq: 16 August 2012 - 08:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 Adidas 777   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 29-July 12

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:38 AM

This is the point !
I only want a location where to put the Interface and where to implement it,
i'm not asking 4 HW ...
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:40 AM

And what are you talking about with the "all pack" ? That is just meaningless.

View PostAdidas 777, on 16 August 2012 - 09:38 AM, said:

This is the point !
I only want a location where to put the Interface and where to implement it,
i'm not asking 4 HW ...


You would define an interface class in its own file. Look at the link to the Interface class that I already provided to you.

Curtis is right that we don't have near enough to go on to be able to help you.
Was This Post Helpful? 0
  • +
  • -

#6 Adidas 777   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 29-July 12

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:41 AM

More specific

namespace Conversion
{
    /// <summary>
    /// Interaction logic for Mainwindow.xaml
    /// </summary>
    /// 

    interface ICalculate
    {
        //implementing the entered sum conversion
        int CalculateConversion(int a , int B)/>;
    }

    public partial class MainWindow : Window,ICalculate
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btConvert_Click(object sender, RoutedEventArgs e)
        {
            int a = 1;
            int b = 2;


        }

        
        
    }
        //??? Where to put this !?
        public int CalculateConversion(a,B)/>
        {
            return a+b;
        }
}

Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5105
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:42 AM

You put the method inside the class that implements the interface.
Was This Post Helpful? 1
  • +
  • -

#8 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:45 AM

Tip: Those control names of button_1 and so on are just aweful and will only make your life hard. See the tips below for idea on how to better name things.


Some of my common tips (some may apply more than others to your specific style):
  • You have to program as if everything breaks, nothing works, the cyberworld is not perfect, the attached hardware is flakey, the network is slow and unreliable, the harddrive is about to fail, every method will return an error and every user will do their best to break your software. Confirm everything. Range check every value. Make no assumptions or presumptions.

  • Take the extra 3 seconds to rename your controls each time you drag them onto a form. The default names of button1, button2... button54 aren't very helpful. If you rename them right away to something like btnOk, btnCancel, btnSend etc. it helps tremendously when you make the methods for them because they are named after the button by the designer.btnSend_Click(object sender, eventargs e) is a lot easier to maintain than button1_click(object sender, eventargs e)

  • You aren't paying for variable names by the byte. So instead of variables names of a, b, c go ahead and use meaningful names like index, timeOut, row, column and so on. You should avoid 'T' for the timer. Amongst other things 'T' is commonly used throughout C# for Type and this will lead to problems. There are naming guidelines you should follow so your code confirms to industry standards. It makes life much easier on everyone around you, including those of us here to help. If you start using the standards from the beginning you don't have to retrain yourself later.
    You might want to look at some of the naming guidelines. Its a lot easier to start with good habits than to break bad habits later and re-learn.



  • Try to avoid having work actually take place in GUI control event handlers. It is better to have the GUI handler call other methods so those methods can be reused and make the code more readable. This is also how you can send parameters rather than use excessive global variables. Get in this habit even if you are using WinForms because WPF works a lot under the idea of "commands" and this will get you working towards that. Think of each gester, control click, menu option etc. as a command to do something such as a command to SAVE. It doesn't matter where the command comes from, all sources should point at the same target to do the actual saving.
    Spoiler


  • Don't replace lines of code that don't work. Instead comment them out and put your new attemps below that. This will keep you from re-trying the same ideas over and over. Also, when you come back to us saying "I've tried this 100 different ways and still can't get it", we can actually see what you tried. So often a failed attempt is very very close and just needs a little nudge in the right direction. So if we can say "See what you did in attempt 3... blah blah" it helps a lot

    Spoiler

    If you are using Visual Studio you can select a block of lines and hit control+k control+c (Kode Comment) to comment it out. control+k control+u (Kode Uncomment) to uncomment a selected block.


View PostAdidas 777, on 16 August 2012 - 09:41 AM, said:

More specific

        //??? Where to put this !?
        public int CalculateConversion(a,B)/>
        {
            return a+b;
        }
}


MSDN Example shows this very well:
http://msdn.microsof...ibrary/ms173157
Was This Post Helpful? 1
  • +
  • -

#9 Adidas 777   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 29-July 12

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:47 AM

tlhIn`toq Thanks 4 your help !!!

Can you please tell me where to put the implementation ?
I know how to do this in Console application but in WPF I don't /:
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 08:57 AM

As Curtis said, you put it in the Class that is implimenting the interface. Examples right out of the MSDN link I gave you. Did you even look? Do you not understand what you are reading?

interface IControl
{
    void Paint();
}
interface ISurface
{
    void Paint();
}
class SampleClass : IControl, ISurface
{
    // Both ISurface.Paint and IControl.Paint call this method. 
    public void Paint()
    {
    }
}


public class SampleClass : IControl, ISurface
{
    void IControl.Paint()
    {
        System.Console.WriteLine("IControl.Paint");
    }
    void ISurface.Paint()
    {
        System.Console.WriteLine("ISurface.Paint");
    }
}



interface ILeft
{
    int P { get;}
}
interface IRight
{
    int P();
}

class Middle : ILeft, IRight
{
    public int P() { return 0; }
    int ILeft.P { get { return 0; } }
}


If you don't follow those very direct and simple samples then you need to go to your instructor. Make him/her earn their paycheck by explaining this to you because we can't provide example that are any more clear than these two without actually doing your homework for you and we don't do that at DIC.
Was This Post Helpful? 0
  • +
  • -

#11 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5105
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Interface "All Pack" with WPF Application

Posted 16 August 2012 - 09:04 AM

Quote

I know how to do this in Console application but in WPF I don't /:


There's literally no difference with interfaces in any project type. The project types are just templates and different output. The mechanics of the language are always the same. Interfaces are interfaces, whether a console app, forms app, silverlight app, or web app. And classes implement interfaces exactly the same way, no matter what.
Was This Post Helpful? 1
  • +
  • -

#12 Adidas 777   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 29-July 12

Re: Interface "All Pack" with WPF Application

Posted 17 August 2012 - 12:49 AM

Thank you 2 :)
You helped me a lot !!! :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1