What’s a good test Tax File Number (TFN)?
555-000-555. Nice and easy to remember.
Wikipedia has some more information on the TFN algorithm: http://en.wikipedia.org/wiki/Tax_File_Number.
What’s a good test Tax File Number (TFN)?
555-000-555. Nice and easy to remember.
Wikipedia has some more information on the TFN algorithm: http://en.wikipedia.org/wiki/Tax_File_Number.
Well done David and team!!
Winners of the Imagine Cup 08 in France.
http://www.microsoft.com/presspass/events/imaginecup/images/9932.jpg.
To re-size the container DIV of a Silverlight control so that it stretches depending on how much content is in the Silverlight application is quite easy.
In this example we will use an ItemsControl which loads comments from a WCF service. As more comments are added we want my Silverlight control to continually expand.
Silverlight control in the ASPX page
<div id="commentsSection"> <asp:Silverlight ID="MyCommentsControl" runat="server" Source="~/ClientBin/MyCommentsApp.xap" MinimumVersion="2.0.30523" Width="400" Height="100%" /> </div>
Note the DIV with an ID around the Silverlight control. Also the Silverlight control height property is set to 100%.
ItemsControl Example
Inside the Page.xaml file create the ItemsControl.
<ItemsControl VerticalAlignment="Top" x:Name="Comments" Grid.Row="1" > <ItemsControl.ItemTemplate> <DataTemplate> <my:Comment x:Name="CommentItem"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>
The my:Comment user control simply shows a few TextBlocks in a StackPanel.
Wire up resize events and logic
When the ItemsSource is set on the ItemsControl we want the Silverlight control itself to expand and push down the HTML page. To do this we need to hook up an event handler to the ItemsControl SizeChanged event.
public Page()
{
InitializeComponent();
this.Comments.SizeChanged += new SizeChangedEventHandler(Comments_SizeChanged);
}
void Comments_SizeChanged(object sender, SizeChangedEventArgs e)
{
double acutalHeight = this.Comments.ActualHeight;
HtmlPage.Document.GetElementById("commentsSection").SetStyleAttribute("height", string.Format("{0}px", acutalHeight));
}
Add the SizeChanged under the call to InitializeComponent(). Within the SizeChanged event handler you can see the code to get the ActualHeight of the comments. Next the element we created in the ASPX page is updated using the JavaScript bridge.
Bind data and call UpdateLayout()
Finally we need to bind some data to the ItemsControl.
void cClient_GetCommentsCompleted(object sender, SLComments.CommentsService.GetCommentsCompletedEventArgs e)
{
Comments.ItemsSource = e.Result;
this.Comments.UpdateLayout();
}
Take special note here of the call to this.Comments.UpdateLayout();. This must be called after the ItemsSource is set to ensure the SizeChanged event is fired.
Every time you bind the ItemsSource the parent DIV will re-size and because the Silverlight control height property is set to 100% in the ASPX page it will re-size with it!
You create a new Silverlight WCF service and a snazzy new Silverlight application to access it to do all this cool stuff. You go in and add a Service Reference, click discover and it automatically finds your WCF for you. You wire up the events and code to make a call to the service…
You run up your Silverlight application and BAM – 404! But shouldn’t it just work?
Well if you get this problem it’s probably cross domain policy raining down on your parade. It kicks in when the domain you are requesting from is not the same as the domain you are requesting to. And yes, this may have just happened even though you aren’t exactly running a root DNS server in your bedroom at mum’s house.
What may be happening is that you are pressing F5 in Visual Studio, which then fires up your app on http://localhost/MyAwesomeApp – but in your Silverlight ServiceReferences.ClientConfig the endpoint address is set to http://devboxoftotalawesome/getrichquick/WebServices/Comments.svc.
Change this to the same URL that Visual Studio fires up your web site (and service) on and voila, your awesome WCF messages spill down the wire.
You may also want to consider editing your cross domain policy file – see the lovely Karen’s article here on this: http://scorbs.com/2008/04/15/silverlight-http-networking-stack-part-2-cross-domain-communication-overview/. Although this will fix the issue, remember that in production you probably do not want to go down this route unless you really do intend outside apps to access your services.
Also keep in mind that the cross domain policy file only works for (web)clients that adhere to it – such as Silverlight and Flash (Flash policy file). It’s important that note that adding a cross domain policy file does not protect your service from nefarious users… it merely prevents Silverlight and Flash apps from accessing your services. The only way to protect your sevices and other data sources from misuse is to apply security – like user authentication etc.
Looks like Manning are in the final stages of preparing Silverlight 2 in Action.
Amazon has pre-order available here.
I personally have loved the * in Action books I have read (LINQ in Action and ASP.NET AJAX in Action) and I will be pre-ordering this book soon.