in

ExpressionBlog.com

Microsoft Expression Studio Community

This Blog

Syndication

Mirrored Blogs

Browse by Tags

All Tags » JavaScript (RSS)
  • Webcast Follow-up - CreateFromXAML

    Today's Webcast focused on factoring out repeated creation of objects in XAML (and their manipulation in the code behind) by creating objects dynamically using CreateFromXaml (This will be available for viewing as soon as the recording is processed). The webcast began by showing this application , that uses animation to display changes in data over time. It then explored the problems with this approach and offered a solution as shown in this video . During the course of the webcast I mentioned a number of postings that you may want to read: A tip of the day covering CreateFromXAML Tip of the Day showing that you can retrieve the Silverlight control (plugin) using GetHost() Brief Tip of the Day pointing to information about the Silverlight control's content sub-object Introductory Video on using Silverlight with Web Services More advanced video that uses Silverlight with Web Services, AJAX and JSON Thanks again.
  • Adam Kinney's Too Great To Miss Tutorial on Making a Chart In 1.0

    Do not miss Adam Kinney's excellent tutorial on creating a bar chart in Silverlight 1.0; it is brilliant, and it is a great staring point on working with XAML, JavaScript, JSON data and many other interesting aspects of Silverlight . Also, while I have you, a quick apology; in my haste to put up today's Tip of the Day I posted a msg. that I would be late; brainlessly forgetting that said message would be sent out via RSS wasting everyone's time and bits. Won't happen again.
  • Tips of the Day: Setting properties in custom controls in 1.0

    Got a nice international email today that said in part... ...things get more interesting it is a common scenario to write custom controls....I need to specify the parameters in code behind. Can I create custom xaml tags which are connected to the code-behind? ... I mean something like... <myButton width="100" height="20" Text="Hello World" /> Is this possibly for 2.0? Assuming I understand this, it is no problem and you don't have to wait for 2.0. Fire up Visual Studio, create a new 1.0 application, clean out the XAML and the code behind and add this crude custom button: In this XAML file we create a custom button that is composed of a canvas enclosing a rectangle (the shape of the button) and a TextBlock (to hold the text of the button). Our initial settings make for a somewhat simple button, Our goal is to set some of the properties of this button from within the Javascript. This we can do. The first step is to get a reference to the Button and to its component parts, from within the JavaScript. We'll do that by using the FindName method of the content subpart of the Silverlight control that is passed as a parameter into the handleLoad event handler, fired when the Silverlight control is first loaded. In order to remember the names, I'll split the visual studio editor into two panes (a handy option) so that I can see the code and the code-behind at the same time. (There's a lot to go over in the next figure, we'll take it one piece at a time) You can see the one to one relationship between the names of the Button and its parts in the XAML and the string passed to FindName in the JavaScript (highlighted in yellow). (Remember that the first parameter passed to handleLoad, plugIn, is a reference to the Silverlight control itself. This reference can also be obtained by calling GetHost() on any Silverlight object .) Once we have a reference to all three objects, we set up an event handler for the button. In yesterday's Tip of the Day I hooked up an event handler in the XAML file, and that could have been done here, but I prefer to have the event handlers "wired up" in the code behind because that is where they are implemented, and that allows me to encapsulate the handler and its relationship to the object in one place (if I change the handler's name, for instance, I only have to update one file). Note that this code behind is using the pseudo-object oriented form of Javascript. If this...
  • Did You Know... How to create XAML objects in Javascript?

    I have had a very strong positive reaction to focusing on the Javascript in code behind for Silverlight 1.0, and so will devote not only today's Tip of the Day to a bit more on the topic, but will make sure that I do so on a frequent basis for a while. Before I start: a small house keeping measure: the convention of starting every Tip of the Day with "Did You Know" is getting old. Thus, starting with the very next one it will be replaced with Tip Of The Day: A reader (let's call this one Joe) writes, What I've had trouble understanding is a small bit of code.... Now, I have to say that the best way to get this kind of question answered is to post it to our forums ; that way a lot more people see it a lot more quickly; but since you did write to me, I'll feel free to use it as grist for the Tip of the Day mill... sender.fill = createLinearGradientBrush(sender.getHost(), sender); function createLinearGradientBrush(plugin) { var xamlFragment = '<RadialGradientBrush>'; xamlFragment += '<GradientStop Color="LimeGreen" Offset="0.0" />'; xamlFragment += '<GradientStop Color="Green" Offset="1.0" />'; xamlFragment += '</RadialGradientBrush>'; return plugin.content.createFromXaml(xamlFragment, false); } I understand 'what' it is doing and i understand 'why' it is doing it, but I don't know 'how'... I found the code to do it on a forum return plugin.content.createFromXaml(xamlFragment, false) It isn't surprising you're baffled by this code as it is pretty advanced and it starts in the middle. sender.fill = createLinearGradientBrush(sender.getHost(), sender); What can we see or guess? 1. the purpose of this line is to fill sender with a LinearGradientBrush. 2. the LinearGradientBrush will be created by the function createLinearGradientBrush. 3. The function createLinearGradientBrush takes two parameters: the getHost() method of the sender and the sender itself 4. The function crateLinearGradientBrush returns a Brush (and it better be a LinearGradientBrush or someone should be hurt) that be assigned to the sender's fill property. What is sender? It's not a big leap to assume sender is a shape. How did we get here? We assume "here" is the middle of some function, and sender was a parameter to that function. To do this right, I think we want to create a simple application that might get us to just this...