Posted by Joe on May 3, 2008
I tried out the step-by-step example by Michael Sync for getting data into a datagrid in Silverlight via webservices. I skipped some steps as I already had a database set up, and I adapted the code to my specific needs. I’m very, very glad to say, though, with very little difficulties, it worked. I did have to surmise a few things, so I’ll jot them down here.
- You’ll need to create the ListingControl.xaml file. The easiest way would be to rename the default Page.xaml that’s created in the Silverlight project.
- In the ListingControl.xaml file, rename the default <Grid> from “LayoutRoot” to “ListingControl”
- Add a “Loaded” event to the <Grid> and choose the default name (ListingControl_Loaded)
- Add a DataGrid to the ListingControl.xaml file.
Here’s the code for the XAML file:
<UserControl xmlns:my=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data” x:Class=”SLTwo.Page”
xmlns=”http://schemas.microsoft.com/client/2007“
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml“
Width=”400″ Height=”300″>
<Grid x:Name=”ListingControl” Background=”White” Loaded=”ListingControl_Loaded”>
<my:DataGrid x:Name=”CustomersDataGrid” Grid.Row=”1″ Margin=”5″ AutoGenerateColumns=”True” />
</Grid>
</UserControl>
- Note that you may have a different solution name than the example (S2WebSrv). Mine was named SLTwo, so I had to change that in the <UserControl> tag.
- Be careful with your XML. My data had ampersands in various places, so I had to change the line of code in the RetrieveProduct method of the web service that adds the product name to the XML so it replaces “&” with “&”. The XDocument.Parse method choked on the XML it was receiving, but didn’t say why. Ugh.
Phew! What a long road just to get data flowing into a Silverlight app. Glad to say, with Michael Sync’s help, that obstacle has been overcome. Now, on to better things. Maybe I’ll try hooking up NHibernate to the ASP.NET project and play around with some more interactive content.
‘Til next time!
Posted in Silverlight | Tagged: Silverlight, web services, xml | 1 Comment »
Posted by Joe on May 2, 2008
I won’t rant too much here. Just updating on my latest endeavors with Silverlight. I was trying to wire up my test app to a MySQL database, but discovered you can’t easily do that because you can’t use a .dll (e.g. the MySql.Data.dll) in a Silverlight Application. That’s kind of a bummer. It turns out the Silverlight way of connecting to any data source is through a web service.
I have no real issues with this, except I wonder how performance will be on larger datasets. I’ll have to run some tests once I get it working . . . IF I get it working. For the life of me, I can’t get web services to work. I’ve seen a few dozen examples, but when trying to implement them myself, I run into blocks all the way. Hooking up to a standard .NET web service (.asmx) is painful, but doable. Looks like Silverlight prefers the WCF-style web service and Linq.
I coded up a WCF web service, then used Linq in Silverlight to read the data returned from the web service. Note, however, that I made an assumption that I would create one true .NET solution (non-Silverlight) that handled the data access and web service portion, and consume that web service in Silverlight. Alas, no . . . at least not by adding a service reference to my web service in the Silverlight app. I get a message stating the service needs to be in the same context. I don’t know what this means, and by this point, I’m quite frustrated with the whole thing, so I’ve taken a bit of a sabbatical from it.
I have a strong suspicion that I’m missing something important. Even trying to adapt the Digg example from Scott Guthrie left me a little bewildered that my own code was having so many troubles. That said, I just found another example from Michael Sync that I’m going to take a look at. It looks a lot more thorough at first glance. I’ll blog about my results with this soon.
Posted in Silverlight | Tagged: Silverlight, web services | 1 Comment »
Posted by Joe on April 22, 2008
Believe it or not, some of the controls in Silverlight don’t have a double-click event. ListBox is one of them. I am astounded. And, no, ListBoxItems.MouseDoubleClick doesn’t work. So, as usual, I went on my quest to find out how to get double-click to work.
Thanks to a fellow by the name of David Kelley and his blog, HackingSilverLight, I found what I was looking for. Yes, it’s a hack, but a pretty good one, I must say. Take a look at it for yourself here:
http://hackingsilverlight.blogspot.com/2008/02/silverlight-20-double-click-support.html
Posted in Silverlight | Tagged: double-click, listbox, Silverlight | Leave a Comment »
Posted by Joe on April 20, 2008
Yesterday, I installed Silverlight 2 beta 1 for Visual Studio 2008 with the latest version of Silverlight Tools. No issues with the install. I was all ready to start developing something simple, yet cool. Opened VS2008, started up a new Silverlight Application, got the Silverlight environment in front of me, along with the Silverlight Toolbox. First, let’s try adding a label. Oh, wait . . . can’t do that. Labels have been deprecated in WPF in favor of the TextBlock. Ok. Let’s add that. Click on TextBlock, go over to the designer area, attempt to draw a new TextBlock. Nothing. Hmm. Ok, clicked on TextBlock and dragged over to the designer area and dropped. Nothing. Hmm.
Turns out, after searching for others with this problem, that currently, you can’t drag ‘n’ drop into the designer area. You can, however, drag ‘n’ drop into the XAML markup area, and your XAML tags will show up just fine. Ok. That works. Of course, the downside is that you have to position everything very manually for the moment. I guess I can live with that since I am a hand-coder anyway for HTML. Shouldn’t be much different.
I’m glad to say that I was able to set up a quick little app that doesn’t do a whole lot . . . just presents a TextBlock, a TextBox and a Button. Now, I’m off to wire it up to something interesting . . .
Posted in Silverlight | Tagged: drag n drop, Silverlight, toolbox | Leave a Comment »