.NET Blog

Tony Cavaliere

 
My Favourite Albums
  And the Grappa wins.
E-mail me Send mail
Add to Technorati Favorites AddThis Feed Button

Subscribe to Cynot Why Not


Recent posts

Disclaimer

Hey unlike other bloggers I stand by what I say but just in case. The opinions expressed herein are my own except on Tuesday when the second card is not turned up otherwise it ain't worth squat.

© Copyright 2010

Expression 3 Screen Capture – Dual Monitor

I’ve been playing around with Expression 3 Encoder and Screen Capture and I must say, pretty impressive. The screen capture is extremely easily to use and has build-in support for overlays. In fact, the PIP webcam feature is automatically overlayed onto the video. This makes it easy to include the presenter in a small window, the location of which can be configured.

One thing that surprised me was the recognition that I was running dual monitor and that Expression Screen Capture was able to capture both screens. Wow!

Below are two videos, hosted on Silverlight Streaming, I capture using Expression 3. The video on the left shows the capture of the dual monitors, while the second contains a capture of a high definition video. Unfortunately, Expression 3 Encoder does not support the Publish To Silverlight Streaming option. I had to manually upload the videos to the Silverlight Streaming Service. Hopefully that plug-in will be made available shortly.

To enter full screen mode double click. Likewise, to exit full screen double click again.

Expression 3 has taken video to the next level!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Expression | Silverlight
Posted by CynotWhyNot on Wednesday, September 02, 2009 10:27 PM
Permalink | Comments (2) | Post RSSRSS comment feed

Calling Complex jQuery from Silverlight: Eval to the Rescue

In an earlier post I described how you can call jQuery from within a Silverlight application. The process is rather simple as was the example. Please refer to the original post for further details.

Afterwards I began to think about calling more complex jQuery constructs from within Silverlight. What about registering events and using anonymous functions? At first glance it didn’t seem it was going to work at least not with the technique I described in my earlier post. Then I discovered the dark side of Javascript the Eval function. The Silverlight HtmlPage.Window object exposes the Eval function that allows you to evaluate any string.

I added the following line of code to my the Page constructor for the example from my previous post.

   21    HtmlPage.Window.Eval("$('#hello').click(function() { alert('Eureka'); });");

This code basically registers a click event with the DOM element with id of #hello. When the DOM element is clicked an alert is displayed and it works perfectly well.

As with raw Javascript all the pros and cons with the use of Eval exist when used from within Silverlight. But it’s good to know that if required complex Javascript functionality can be implemented from within Silverlight.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: jQuery | Silverlight
Posted by CynotWhyNot on Friday, March 20, 2009 10:41 AM
Permalink | Comments (22) | Post RSSRSS comment feed

Calling jQuery directly from Silverlight

Last night I gave a jQuery presentation at TVBUG and I was asked whether you could call the jQuery API directly from within Silverlight. My initial response was yes, but I had promise the person that I would create a demo and blog about it.

Calling Javascript from within Silverlight control involves the following steps;

  1. Add a using System.Windows.Browser namespace to the code behind of the Silverlight control.
  2. Creating a ScriptObject by calling HtmlPage.Window.CreateInstance.
  3. Calling the Invoke method off the ScriptObject from step 2.

Let’s look at some code.

The listing below contains a code snippet that is run when a Silverlight button is clicked.

   23  private void btn_Click(object sender, RoutedEventArgs e)

   24  {

   25    ScriptObject js = HtmlPage.Window.CreateInstance("$", new string[] { "#hello" });

   26    js.Invoke("css", "background-color", "#00FF00");

   27    js.Invoke("css","border","5px solid #FF0000");

   28  }

Notice the parameters to the HtmlPage.Window.CreateInstance static member shown on line 25 contains the call to jQuery function $() and the selector #hello. This call returns a ScriptObject and can subsequently be used to invoke functions off the jQuery object. In this example, I am first setting the background of the DOM element with id of hello to red and then setting it’s border.

I have a working demo of this just navigate to this site.  

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: jQuery | Silverlight
Posted by CynotWhyNot on Wednesday, March 18, 2009 4:36 PM
Permalink | Comments (26) | Post RSSRSS comment feed

Merry Christmas and Happy New Year

I hope everyone had a wonderful Christmas.

I was designated cook at my family's gather and as tradition, on Christmas eve, we have a seafood feast. First on the menu was Mussels Ala Marinara served with crustinies. This was followed with garlic shrimp, calamari and the main dish salmon with butter amaretto sauce.

On Christmas day I visited my cousin's home and spent the day with my relatives. It was a joy to see everyone especially the children. Santa was good to them and you could see it on their faces.

But what does this post have to do with .NET? Well nothing, really, but if you need a dose of .NET then visit my  Deep Zoom Holiday Site  and see if you can find some of my family members!

Enjoy the rest of the holiday's.

Guess the movie

You see George, you've really had a wonderful life. Don't you see what a mistake it would be to just throw it away?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Silverlight
Posted by CynotWhyNot on Saturday, December 27, 2008 8:14 AM
Permalink | Comments (11) | Post RSSRSS comment feed

Using an Intermediary to implement binding between Silverlight controls

WPF has built-in support for binding UI elements. For example, when the user changes the position of the slider the width of the button changes, all done through binding in XAML. Unfortunately, Silverlight does not have this built-in support. So what can be done?

Using an intermediary class and generics it is fairly simple to roll your own. Let's take a look at how it works.

Using VS2008 create a Silverlight application. I called the project BindingBetweenUIControls, rename the TestPage's to default and am using VB.NET. Next, in the Silverlight project, add a class called IntermediaryUIBinding.vb. Figure 1 shows the solution explorer.

Figure 1: Solution Explorer

solution  

Edit the class InterediaryUIBinding.vb. Listing 1 shows the complete listing of this class.

Listing 1: The class IntermediaryUIBinding used to bind UI controls.

    1 Imports System.ComponentModel

    2 

    3 'Intermediary class used to binding to UI properties of type double.

    4 Public Class IntermediaryUIBinding(Of T)

    5     Implements INotifyPropertyChanged

    6 

    7     Public Event PropertyChanged( _

    8         ByVal sender As Object, _

    9         ByVal e As System.ComponentModel.PropertyChangedEventArgs) _

   10         Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

   11 

   12     Private _IntermediaryValue As T

   13     Public Property IntermediaryValue() As T

   14         Get

   15             Return _IntermediaryValue

   16         End Get

   17         Set(ByVal value As T)

   18             _IntermediaryValue = value

   19             RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("IntermediaryValue"))

   20         End Set

   21     End Property

   22 

   23     Public Sub New(ByVal value As T)

   24         IntermediaryValue = value

   25     End Sub

   26 

   27 End Class

This generic class implements INotifyPropertyChanged which is a requirement if you want to provide two way data binding. Please refer to the previous post Silverlight Data Binding, using INotifyPropertyChanged and ObservableCollection. The generic implementation permits this class to be used for UI properties of various types. In this example we will be binding a double value. The actual class implementation is extremely simple containing a single property that raises the PropertyChanged event whenever the value is modified. This event is used by the binding infrastructure to notify the UI of data changes.

The UI for this Silverlight control is shown in listing 2.

Listing 2: Page.xaml with the UI data binding markup.

    1 <UserControl x:Class="BindingBetweenUIControls.Page"

    2    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    3    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    4    >

    5     <Grid x:Name="LayoutRoot" Background="Bisque" Width="400" Height="300">

    6         <Grid.RowDefinitions>

    7             <RowDefinition Height="150"/>

    8             <RowDefinition/>

    9             <RowDefinition/>

   10         </Grid.RowDefinitions>

   11         <TextBlock FontSize="18" TextWrapping="Wrap" Margin="10">

   12             <Run>Using an intermediary object you can bind properties of controls.</Run>

   13             <Run>Change the slider position and watch the button width change.</Run>

   14         </TextBlock>

   15         <Slider

   16            x:Name="bindingSlider"

   17            Value="{Binding IntermediaryValue, Mode=TwoWay}"

   18            Width="300" Minimum="100" Maximum="300"

   19            Grid.Row="1" />

   20         <Button

   21            x:Name="bindingButton"

   22            Width="{Binding IntermediaryValue}" Height="50"

   23            Content="Binding UI" Grid.Row="2" />

   24     </Grid>

   25 </UserControl>

The markup contains two controls; a slider and a button. The slider, line 17,  has it's Value attribute bound to the IntermediaryValue property and uses two way data binding. Similarly , the button control, line 22, has it's Width attribute bound to the same IntermediaryValue property but does not use two way data binding. The two way binding for the slider is necessary since we want the underlying data stored in the property  IntermediaryValue to change whenever the slider position is changed by the user.

Finally, all that needs to be done is to set the DataContext of a parent control. This is easily done in the code behind of Page.xaml and is shown in listing 3.

Listing 3: Page.xaml,vb Codebehind

    1 Partial Public Class Page

    2     Inherits UserControl

    3 

    4     Public Sub New()

    5         InitializeComponent()

    6     End Sub

    7 

    8     Private Sub Page_Loaded( _

    9         ByVal sender As Object, _

   10         ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded

   11         LayoutRoot.DataContext = New IntermediaryUIBinding(Of Double)(bindingSlider.Value)

   12     End Sub

   13 

   14 End Class

Fairly simple, line 11 sets the DataContext of the grid control to an instance of the Intermediary class specifying a generic type of Double. The constructor parameter specifies the initial value of the slider. Now when the users changes the position of the slider the binding infrastructure will update the underlying data store, i.e., the property  IntermediaryValue and since this property is bound to the button's width it will change accordingly.

That's it binding between Silverlight UI controls.

This post was inspired by a presentation by Dan Borkowski at the Toronto Silverlight User Group.

If you would like to see this code in action or would like to download the code then visit my Silverlight Demo Gallery.

Guess the movie

Where do you think you're going? Nobody's leaving. Nobody's walking out on this fun, old-fashioned family Christmas. No, no. We're all in this together. This is a full-blown, four-alarm holiday emergency here. We're gonna press on, and we're gonna have the hap, hap, happiest Christmas since Bing Crosby tap-danced with Danny fucking Kaye. And when Santa squeezes his fat white ass down that chimney tonight, he's gonna find the jolliest bunch of assholes this side of the nuthouse.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Silverlight
Posted by CynotWhyNot on Thursday, December 04, 2008 3:30 PM
Permalink | Comments (16) | Post RSSRSS comment feed