Wednesday, November 26, 2008

Silverlight Threading and Events

$##$%^#$% Silverlight today is really making me tired. So I have this textbox? no big deal tha tis a search form. Users expect the return to make the form 'submit'. we know that is not exactly how Silverlight forms 'work' persay but we get the point right. no problem nothing a bit of code won't solve. so I make the 'search' button have a click event that validates the form and sents it to a class that deals with the data. and it works great.

then I make the text block have a keydown event so I can capture returns and send them along their way... if it is a return I just call the other event handler...

and one does a call to system which blows up. so the event in the key up looks like this:


private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
SearchBtn_Click(sender, null);
}
}

but in the search btn we are trying todo an alert as I'm in a hurry and don't feel like making a nice silverlight message thingy so I just want todo this:


private void SearchBtn_Click(object sender, RoutedEventArgs e)
{
string SearchValue = SearchBox.Text.ToString();
if (SearchValue != "" && SearchValue.Length > 2)
{
DataBindMe.DataContext = CrossfaderUsers.RetrieveSearchUserList(SearchValue);
}
else
{
System.Windows.Browser.HtmlPage.Window.Alert(App.SEARCHTEXTINVALID);
}
SearchMessageBox.Visibility = Visibility.Collapsed;
}

this blows up from the keydown event apperently as it is not on the UI thread??? WT...? I mean really the 'click' event is on the UI thread but keydown is not? the error message is something to effect of namespace 'System' is not accessable due to the context? As far as I can tell by 30 minutes of googling is that this event some how is magically not on the UI thread so when I add this:


Dispatcher.BeginInvoke(delegate()
{
System.Windows.Browser.HtmlPage.Window.Alert(App.SEARCHTEXTINVALID);
});

it magically works???

Monday, November 24, 2008

Silverlight 2 Event bindings

So in the process of working on this presentation for dev teach and the article and the book I got in a long discussion with alot of the ubber guys I work with around event binding in Silverlight. In that spirit I would like to get everyones input or at least some ones on what they think about where event bindings should take place....

checkout my post on dotnetslackers and let me know:

http://dotnetslackers.com/Community/forums/silverlight-architectural-best-pratices/t/2609.aspx

Friday, November 21, 2008

Silverlight 2 Architecture and CodeCamp

So I was going todo a couple of sessions recently at a seattle local even called codecamp. I had a family related complication and was not able to attend (I did let the organizers know BEFORE it started, so don't go harping on me for doing it at the last moment).

Anyway one guy emailed me about getting that content available. of course this stuff will be in my book and I'm doing the presentations at DevTeach etc. but up front I'd like to point out a few things that might help get people going in the right direction.

So from a design pattern stand point the entire discussion frequently has more in comon with Hell Fire and brime stone religous discussions then real logical 'Useful' disuccusions that are actually helpful. It really is all kind of esoteric mumbo jumbo at some level.

In an effort not to get sucked into a religous war I'm going to go WAYYYY out of a limb and say the best design pattern is in fact MVP (model view presentor) as discribed in the following posts by others:



Phil Haack
http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx
Tim Ross
http://timross.wordpress.com/2008/03/16/implementing-the-mvp-pattern-in-silverlight/

There are several ways todo it and I'm not even saying that this one is correct just it happens to be my choice for no other reason then it helps get back to some nice old CS101 ideas like 'gasp' OBJECT ORIENTED or Encapsulation sorts of things.

my code behinds are simple may data model objects are clean and my Xaml is Zen with the universe.

lets just say for the sake of moving foward that I'm going with the MVP design pattern as my prescribed method. Alot of what you do on top of that is more or less common sense. Follow stand coding conventions as they apply, following Preformance best practices where they apply, and most of all consistency.

do it, all do it and do it the same...

I really don't care which way but really I should never be able to tell who did and I should seem lots of oh yea that is logical and is the best way.

really thats is the bottom line. More to come as I work out a detailed talk track for the SLV421 presentation in case I want to give it to say my friend John todo the same presentation at another conference... ;)

Thursday, November 20, 2008

Tired of Customers dissing your work?

I saw this on Scott's status on face book a link to this:

http://dotnetpays.computerinnovationsny.com/dotnetpays/Home.aspx

very very cool. My kind of hack. not really 'Silverlight' strickly speacking but a good thing to be aware of.

Seattle Developer / Designer Interactive Group

we had our second meeting last night. I was surprised that we had the same size audience but with alot of new faces. A big part of this was that all the adobe/flash/flex types were at the ubber adobe conference this week. Ariel posted a great post on the happenings at http://www.SeattleD2IG.com

Next month we will focus on mobile devices and we are hoping to get some cool people in this space to talk about their work. Be cool too and show up. :)

Monday, November 17, 2008

CodeMash and DevTeach

Hm... I'm thinking I need to get my outline finished today for DevTeach. I'm exicted about both of these conferences. DevTeach I'm doing 3 sessions as planned but I found out today that I'm also doing a session at CodeMash this year.

DevTeach is giving a bunch of cool stuff to attendee's and I'm planning on having lots of swag to give out too. Now also at Codemash I get todo the same thing. Codemash is in Ohio at this cool resort and I'm doing a presentation on Silverlight 2 Arctectural Best Practices which will probably include some great 'Anti-Patterns' with the ubber Silverlight app Crossfader. If you can come check it out. :)

http://www.codemash.org/

and of

http://www.devteach.com/

both awesome conferences. :)

Friday, November 7, 2008

Crossfader Goes Live

Crossfader is the largest most complicated Silverlight application to date. After a years work finaly is live. Yesterday afternoon in secret the url was changed to point to the real application. most of the dev team spent all day playing with it. Dan the business owner and Darak (Editor In Chief) are working on closing all the artist deals so hopefully all the music content will get all the real artist content loaded over the next few weeks.

As to Silverlight I went through the application and counted 54 distinct screens, dialogs and views currently in the system. Some of these are amagalmations but remember the whole things is one xap. I'm impressed it runs. :) 10 years ago a web application like this even if it wasn't all together was more likely then not going to lock up your computer. Crossfader certainly is next gen stuff and about the experience. Remember this is still just a beta but facebook will have some catching up todo :)

http://www.crossfader.com/

Wednesday, November 5, 2008

Centering Content in Xaml

so the other day i was trying to get some content to be dynamically centered. i noticed that the normal way i did it in beta 2 was not working... but that is what i get for using things in beta. i found a few convoluted ways to do it but found that the center align stuff on grid exists now and not only that but it works... here is what it looks like for my grid to take up' the whole area and my set size canvas to be centered on screen:
<usercontrol class="www.hackingsilverlight.net.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x="http://schemas.microsoft.com/winfx/2006/xaml" uc="clr-namespace:www.hackingsilverlight.net" >

<grid name="LayoutRoot" >


<grid name="ContentArea" verticalalignment="Center" horizontalalignment="Center" >

<canvas width="660" height="300" >

etc...

nice and simple and clean and you don't even have to have a clue what size your UI is. :)

Local Events about Silverlight

My friend Brain from SD2IG sent me some info on a couple of local Silverlight events:


SEAFLEX MEETING Thu Nov 13 6:30pm – Thu Nov 13 8pm http://www.seaflexug.org/ 701 N 34th St, Seattle WA 98103 Created By Seattle Flex User Group (SeaFlex) Description Ryan Stewart, RIA Evangelist will present to us about the new FXG format that will be available with Flex 4. The Intro to Flex portion will cover the Food Drive Resource Locator project developed during the Flex Code Jam at the 2008 Flex360 conference. This is the 2nd anniversary of the Seattle Flex User Group, so we'll be having cake and prizes! Meeting starts at 6:30 pm (for real now) with the Intro to Flex portion, followed by introductions and the main presentation. If you'd like to network or just chit chat, show up a little early ~6:00. _____________________________ PDXUX (Portland User eXperience group) http://pdxux.net/ Next Meeting: "Silverlight 2 Launch Party"
WHEN: Tuesday 11/11/20086:30 p.m. Pizza Dinner (by Microsoft)7:00 p.m. Presentation1515 NW 19th AvePortland, OR 97209

For this month's PDXUX meeting we are celebrating the recent release of Silverlight 2 with a launch party hosted by the folks at North.
Our featured presenter is Tim Heuer, who is a Senior Program Manager for Microsoft Silverlight. He helps build the worldwide Silverlight community and is very passionate about the platform and technology in general. Having over 13 years of experience with Microsoft web technologies, Tim is excited about the opportunities that Silverlight brings for developers and designers and wants to ensure that everyone has the best information and tools available to them for success. Tim can be found online at http://timheuer.com/blog.

Along with Tim's presentation, we'll have several demo stations featuring Silverlight locals Erik Mork, Kelly White, and Jason Mauer. Learn more about Silverlight 2 features and how you can utilize them in your own web applications.

We'll also be talking about BizSpark, Microsoft's brand new program for supporting startups, and how you can get involved.

Tuesday, November 4, 2008

Seattle Code Camp

In a couple weeks there is the Seattle Code Camp in Redmond that I'll be presenting the first versions of the sessions I'm doing at devteach. Early Sunday is the best day for code camp of course as I'm presenting 3 sessions straight with lunch in the middle.

https://seattle.codecamp.us/sessions.aspx#HACKING+SILVERLIGHT+2+

Come check it out and help me get ready for DevTeach.