John's little part of the web

John's home page

 1 2 3 >  Last ›

2012-06-13 10:40:59

I have added a form on an RIA project that I am working on with three combo boxes that are filled using the domain data source.  The problem is the form data already exists at the client when I open the child window.  This means the combo box selected value is set prior to the item source being set and as such the combo box always uses the first item in the selection and also shows the record as being changed.  Both are a problem... I ran across this post which suggested moving the domain data source into the resource section of the XAML but that did not seem to solve the problem.  What I ended up doing is waiting for the domain data source to load and then setting the form data context as below.

XAML Code:

<controls:ChildWindow.Resources>
    <riaControls:DomainDataSource x:Key="dds_countries"
                                  QueryName="GetCountries"
                                  AutoLoad="True">
        <riaControls:DomainDataSource.DomainContext>
            <l:rtDomainContext />
        </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>
    <riaControls:DomainDataSource x:Key="dds_states"
                                  QueryName="GetStates"
                                  AutoLoad="True">
        <riaControls:DomainDataSource.DomainContext>
            <l:rtDomainContext />
        </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>
    <riaControls:DomainDataSource x:Key="dds_residencetypes"
                                  QueryName="GetResidenceType"
                                  AutoLoad="True">
        <riaControls:DomainDataSource.DomainContext>
            <l:rtDomainContext />
        </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>
</controls:ChildWindow.Resources>

<ComboBox Grid.Row="3"
          Margin="3"
          Grid.Column="1"
          DisplayMemberPath="Name"
          SelectedValuePath="Type"
          ItemsSource="{Binding Path=Data, Source={StaticResource dds_residencetypes}}"
          SelectedValue="{Binding Path=ResidenceType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox Grid.Row="7"
          Margin="3"
          Grid.Column="3"
          DisplayMemberPath="Name"
          SelectedValuePath="Abbreviation"
          ItemsSource="{Binding Path=Data, Source={StaticResource dds_states}}"
          SelectedValue="{Binding Path=State, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox Grid.Row="8"
          Margin="3"
          Grid.Column="3"
          DisplayMemberPath="Name"
          SelectedValuePath="Name"
          ItemsSource="{Binding Path=Data, Source={StaticResource dds_countries}}"
          SelectedValue="{Binding Path=Country, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />


Code Behind:

private int LoadCount = 3;

private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
 ((DomainDataSource)this.Resources["dds_countries"]).LoadedData += (s, a) => { this.LoadAddress(); };    
 ((DomainDataSource)this.Resources["dds_states"]).LoadedData += (s, a) => { this.LoadAddress(); };     
((DomainDataSource)this.Resources["dds_residencetypes"]).LoadedData += (s, a) => { this.LoadAddress(); }; }

private void LoadAddress()
{
   if (--this.LoadCount == 0)     
   {
        this.LayoutRoot.DataContext = this.Address;
        ((System.ComponentModel.INotifyPropertyChanged)this.Address).PropertyChanged += (s, a) =>
        {                
            this.OKButton.Visibility = System.Windows.Visibility.Visible;          
        };
    }
}

 

2012-06-12 06:47:50

I am working on a silverlight RIA application and don't want the option to register or remember the user.  Removing the register was stright forward, just collapse the links in the LoginForm.xaml form.  The remember me option was not as stright forward, after some searching I found this, not sure it is the best way but it works.

In the LoginInfor.cs file remove the remember me property which generates an error in the ToLoginParameters function.  In that function just change the function call so it is always true or false depending on need.  Since I don't want it to remember I set it to false.

2012-06-08 09:04:21

Added the MX Toolbox link to the links page, very useful tool set, use it all the time...

http://www.mxtoolbox.com/

2012-05-26 04:34:47

I updated an application recently that use the .NET 3.5 version of the send mail.  This has been working find with gmail for sending mail.

The problem is when I upgraded to .NET 4.0 it gave an obsolete message on the old send mail so I upgrade to the new SmtpClient.

Note the new SmtpClient is in many ways easier to use and gives better error message but needless to say it did not work with gmail, hum!

So after some fighting with the most obvious problem and seaching the net and gmail help I finally changed the port from 465 to 587 and majically it all started to work.  I am not sure why the old send mail worked fine with 465 and the new one only works with 587 but that seems to be the case.

Below is the test code I was using.

class Program
{
    static string UserId = "gmail user id";
    static string UserPw = "gmail password";
    static void Main(string[] args)
    {
        SendMail("<to email>""<from email""Test message""testing testing testing");
    }

    static bool SendMail(string to, string from, string subject, string body)
    {
        var msg = new System.Net.Mail.MailMessage();
        msg.To.Add(new System.Net.Mail.MailAddress(to));
        msg.Subject = to;
        msg.Body = from;
        msg.From = new System.Net.Mail.MailAddress(from);

        try
        {
            // 465 does not work
            var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(UserId, UserPw);
            client.Send(msg);
            return true;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }

        return false;
    }
}

 

2012-04-24 04:48:32

http://social.technet.microsoft.com/wiki/contents/articles/ipv6-survival-guide.aspx

2012-04-13 09:32:22

The below allows you to get a list of the special folders using powerscript...

Found: here

### Start of Script
### Get the list of special folders
$folders = [system.Enum]::GetValues([System.Environment+SpecialFolder])
# Display these folders
"Folder Name            Path"
"-----------            -----------------------------------------------"
foreach ($folder in $folders)
{ "{0,-22} {1,-15}"  -f $folder,[System.Environment]::GetFolderPath($folder)
}
#End of Script

Desktop                C:\Users\user_name\Desktop
Programs               C:\Users\user_name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Personal               C:\Users\user_name\Documents
Personal               C:\Users\user_name\Documents
Favorites              C:\Users\user_name\Favorites
Startup                C:\Users\user_name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Recent                 C:\Users\user_name\AppData\Roaming\Microsoft\Windows\Recent
SendTo                 C:\Users\user_name\AppData\Roaming\Microsoft\Windows\SendTo
StartMenu              C:\Users\user_name\AppData\Roaming\Microsoft\Windows\Start Menu
MyMusic                C:\Users\user_name\Music
DesktopDirectory       C:\Users\user_name\Desktop
MyComputer
Templates              C:\Users\user_name\AppData\Roaming\Microsoft\Windows\Templates
ApplicationData        C:\Users\user_name\AppData\Roaming
LocalApplicationData   C:\Users\user_name\AppData\Local
InternetCache          C:\Users\user_name\AppData\Local\Microsoft\Windows\Temporary Internet Files
Cookies                C:\Users\user_name\AppData\Roaming\Microsoft\Windows\Cookies
History                C:\Users\user_name\AppData\Local\Microsoft\Windows\History
CommonApplicationData  C:\ProgramData
System                 C:\Windows\system32
ProgramFiles           C:\Program Files
MyPictures             C:\Users\user_name\Pictures
CommonProgramFiles     C:\Program Files\Common Files

 

2012-04-11 02:14:24

I have the following code to move to the next control if the return is entered

private void TextBox_PreviewKeyUp(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return)
    {
        e.Handled = true;
        ((TextBox)sender).MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
    }
}

 

2012-03-21 06:04:47

http://csharpsdk.org/

Looks like a interesting project for getting start with Facebook... I have done some work with the PHP ports but not C#, will try this one next time I need this functionallity.

2012-03-12 05:58:52

http://www.khanacademy.org/math/vi-hart/v/pi-is--still--wrong

Interesting concept...

2012-02-28 06:56:45

Seems the IsReadOnly option does not work as expected on the ComboBox.  After a little searching I found that the IsReadOnly option affect the ablity of the user to edit the text in the ComboBox but does not affect the user's ablity to change the selection which is what I wanted.

To work around this first you need to set the IsHitTestVisible to false, setting this option to false means that none of the mouse events are sent to the control so the user can not select a new option.

This does not stop the user for tabing to the control and selecting a new option with the keypad.  So to stop the user from using the keypad I set the IsTabStop option to false also.  This way this control is not on the tab list which means it can't be selected.

So by setting both option the user can not longer change the option in the ComboBox.

 1 2 3 >  Last ›

Search using bing