Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Silverlight 3.0 Question
Message
De
01/02/2010 08:08:34
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Database:
Visual FoxPro
Divers
Thread ID:
01446590
Message ID:
01446883
Vues:
34
>I've got some code here from a book called "Beginning Silverlight 3.0" by Robert Lair. This is really more of a C# question, but it's in a Silverlight application. I don't know why there would be code like the following: (Confirm)sender < -- Why is Confirm contained by parentheses?
>
>Confirm confirmDlg = (Confirm)sender;
>
>Here's the entire code from the c-sharp code-behind page:
>
>
>using System;
>using System.Collections.Generic;
>using System.Linq;
>using System.Net;
>using System.Windows;
>using System.Windows.Controls;
>using System.Windows.Documents;
>using System.Windows.Input;
>using System.Windows.Media;
>using System.Windows.Media.Animation;
>using System.Windows.Shapes;
>
>namespace Ch4_ModalWindow
>{
>    public partial class MainPage : UserControl
>    {
>        public MainPage()
>        {
>            InitializeComponent();
>        }
>
>        private void Button_Click(object sender, RoutedEventArgs e)
>        {
>            Confirm confirmDlg = new Confirm();
>            confirmDlg.Closed += new EventHandler(confirmDlg_Closed);
>            confirmDlg.Show();
>        }
>
>        void confirmDlg_Closed(object sender, EventArgs e)
>        {
>            Confirm confirmDlg = (Confirm)sender;
>
>            if (confirmDlg.DialogResult == true)
>            {
>                this.Result.Text = "Terms and Conditions Accepted";
>            }
>            else if (confirmDlg.DialogResult == false)
>            {
>                this.Result.Text = "Terms and Conditions Not Accepted";
>            }
>
>        }
>    }
>}
>
Cecil,
It is doing that without type checking and assuming that the 'sender' -which is an object- is of type Confirm. It is fair to do that, since two button clicks are working in concert there (one invoking Confirm and other using its result). Now I know that the 'sender' would be 'Confirm' form, to be able to access Confirm type's properties I need to cast it Confirm and parentheses do casting.

sender.DialogResult

wouldn't work because object (sender is object) doesn't have a property called DialogResult.

... (Confirm)sender

Casting to its current type (Confirm) confirmDialog now is of type Confirm which has DialogResult property and such.


If needs to be an analogy done with VFP (not so correct to do):
with this
   .Left = 100
...
Wouldn't benefirt from intellisense, but this one would:
with this as Form
   .Left = 100
...
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform