DCSIMG
November 2009 - Posts - Alex Golesh's Blog About Silverlight Development

November 2009 - Posts

Sela Developer Practice – Take Two

I’m enjoying PDC09 at LA. As a part of Sela representatives here I am participating at lectures and meetings with many key professionals from Microsoft and other companies.

After getting back from PDC I’ll participate at Sela Developer Practice (SDP) – a special conference which will bring the latest news in the development area. Save the dates 27-30 December.

Now I could announce, that all Silverlight session at SDP will be about Silverlight 4!

 

I have very exciting stuff to share and cool demos. As a teaser, could could see what we have already done with Silverlight 4 here or here.

 

So, save the date of the conference! To registration jump here.

Come and see me and my colleagues there, and stay tuned for my upcoming posts from PDC!

 

See you at SDP,

Alex

Silverlight 4: New features overview (Part 5) – DataBinding improvements

Silverlight 4 introduces improvements in DataBinding. between the improvements are IDataErrorInfo support, ability to bind to DataObjects, StringFormat, TargetNullValue, FallbackValue support and many others.

This post will show how to use StringFormat, TargetNullValue and FallbackValue while databinding.

For show the new features I’ve created sample application –> it will display values bounded to number of DependencyProperties defined in code behind.

image

In code behind I’ve created number of Dependency Properties to bind to:

public DateTime DateValue
{
  get { return (DateTime)GetValue(DateValueProperty); }
  set { SetValue(DateValueProperty, value); }
}

// Using a DependencyProperty as the backing store for DateValue.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty DateValueProperty =
    DependencyProperty.Register("DateValue", typeof(DateTime), typeof(MainPage), null);

public float CurrencyValue
{
  get { return (float)GetValue(CurrencyValueProperty); }
  set { SetValue(CurrencyValueProperty, value); }
}

// Using a DependencyProperty as the backing store for CurrencyValue.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty CurrencyValueProperty =
    DependencyProperty.Register("CurrencyValue", typeof(float), typeof(MainPage), null);

public string NullableFiled
{
  get { return (string)GetValue(NullableFiledProperty); }
  set { SetValue(NullableFiledProperty, value); }
}

// Using a DependencyProperty as the backing store for NullableFiled.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty NullableFiledProperty =
    DependencyProperty.Register("NullableFiled", typeof(string), typeof(MainPage), null);

Now let’s see the first sample – StringFormat. It allows to format the value received from bounded property:

<StackPanel Orientation="Horizontal" Margin="5">
            <TextBlock Text="StringFormat Sample:"/>
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding DateValue, StringFormat='dddd, dd-MMMM-yyyy'}"/>
                <TextBlock Text="{Binding CurrencyValue, StringFormat=P}"/>
                <TextBlock Text="{Binding CurrencyValue, StringFormat=Monthly Income \{0:C\}}"/>
            </StackPanel>
</StackPanel>

The TargetNullValue. The value is used in the target when the value of the source is null:

<StackPanel Orientation="Horizontal" Margin="5">
            <TextBlock Text="TargetNullValue Sample:"/>
            <TextBlock Text="{Binding NullableFiled, TargetNullValue='The value is NULL'}"/>
</StackPanel>

The last one – FallbackValue. This value is used when data binding engine is unable to return the value. The most common case for this is wrong source or path:

<StackPanel Orientation="Horizontal" Margin="5">
            <TextBlock Text="FallbackValue Sample:"/>
            <TextBlock Text="{Binding NonExistingField, FallbackValue='The path is not valid!'}"/>
</StackPanel>

Working application:

image image

Sources here.

 

Stay tuned for more.

Alex

Silverlight 4 Quick Tip: Styling application

Silverlight 4 supports default styles. Default styles are styles with TargetType, but without x:Key property set. Those styles will be applied to all controls from corresponding type.

The sample of default (also sometime called anonymous) style:

<Style TargetType="Button">
        <Setter Property="Margin" Value="5"/>
        <Setter Property="Width" Value="100"/>
        <Setter Property="Height" Value="25"/>
        <Setter Property="Background" Value="Red"/>
</Style>

This style will be applied on any button in the scope of the style. If this style will be placed in App.xaml it will be applied on all buttuns in application.

Now let’s style the application with different styles – I’ve created 2 sample Resource Dictionaries to be the “Themes” of my application with a number of styles for different controls. My sample “Theme 1”:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="Button">
        <Setter Property="Margin" Value="5"/>
        <Setter Property="Width" Value="100"/>
        <Setter Property="Height" Value="25"/>
        <Setter Property="Background" Value="Red"/>
    </Style>
    <Style TargetType="TextBox">
        <Setter Property="FontSize" Value="20"/>
    </Style>
    <Style TargetType="TextBlock">
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="Foreground" Value="Blue"/>
    </Style>
</ResourceDictionary>

My sample “Theme 2”:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="Button">
        <Setter Property="Margin" Value="5"/>
        <Setter Property="Width" Value="Auto"/>
        <Setter Property="Height" Value="Auto"/>
        <Setter Property="Background" Value="Blue"/>
    </Style>
    <Style TargetType="TextBox">
        <Setter Property="FontSize" Value="15"/>
        <Setter Property="Foreground" Value="Green"/>
        <Setter Property="Background" Value="Yellow"/>
    </Style>
    <Style TargetType="TextBlock">
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="Foreground" Value="Red"/>
    </Style>
</ResourceDictionary>

Now I’ll show how to apply those dictionaries to the application. Sample UI will be like follows:

<StackPanel x:Name="LayoutRoot" Background="White">
        <StackPanel Orientation="Horizontal">
            <Button Content="Theme 1" x:Name="btnTheme1" Click="btnTheme1_Click"/>
            <Button Content="Theme 2" x:Name="btnTheme2" Click="btnTheme2_Click"/>
            <Button Content="No Theme" x:Name="btnNoTheme" Click="btnNoTheme_Click"/>
        </StackPanel>
        <StackPanel Orientation="Vertical">
            <Button Content="Test"/>
            <TextBlock Text="Some text here..."/>
            <TextBox Text="Some editable text here..."/>
        </StackPanel>
</StackPanel>

image 

On corresponding button event I’ll apply the styles. Both resource dictionaries were added to the project as a Content resources. Let’s see the “Theme 1” button EventHandler:

ResourceDictionary rd = new ResourceDictionary();
//Load resourse dictonary
rd.Source = new Uri("/Theme1.xaml", UriKind.RelativeOrAbsolute);
//Clear previous styles if any...
App.Current.Resources.MergedDictionaries.Clear();
//Add the loaded resource dictionary to the application merged dictionaries
App.Current.Resources.MergedDictionaries.Add(rd);

The second theme is exactly the same. To “Clean” the themes from application just clear MergedDictionaries:

App.Current.Resources.MergedDictionaries.Clear();

Running application:

image

image

Application source here.

 

Stay tuned for more features how-to’s and tips

Alex

Silverlight 4: New features overview (Part 4) – Out-of-browser applications: even more features

In addition to previous features, Silverlight 4 adds some more nice improvements to Out-of-Browser model.

Now it allows to control Top/Left position of the out-of-browser window, bring it to the foreground (if not active), check if the window is topmost and define it’s Width/Height.

All those features being exposed by MainWindow object of Application:

image

Additional feature is Notification Window. It is a notification area that is displayed in the system area, at the bottom right part of the screen. In application described at previous post (here) I’ve added a button to show notification window.

image

I’ve added and Silverlight control to the project, and it will be the UI of my notification window:

image

At the “Notification” button event handler:

if (App.Current.IsRunningOutOfBrowser)
{
    NotificationWindow nw = new NotificationWindow();
    nw.Width = 250;
    nw.Height = 100;
    nw.Content = new Toast();
    nw.Show(5000); //Show the window for 5 seconds
}

Running application:

image

Sample code here (also for the previous Elevated Out-of-Browser post).

 

Stay tuned for the next part – DataBinding improvements.

Enjoy,

Alex

Silverlight 4: New features overview (Part 3) – Elevated Out-of-browser applications

Silverlight 4 enhances the out-of-browser feature introduced in previous version of the technology. Silverlight 3 added a feature to use application in Out-of-browser mode – install application shortcut to desktop or start menu, and launch it within application launcher (instead of the browser). Along with it, the application still was sandboxed application, with the same set of restrictions, like in browser.

Silverlight 4 extends this feature and allows to relax some of the sandbox restrictions while running application with elevated permissions.

First, let’s see what will be allowed under elevated permissions…

The runtime will allow:

  • Cross domain network access with policy file check
  • Getting full file path from Open/Save file dialog
  • Access to users folders, like MyDocuments
  • COM Interop
  • HTML hosting support

Now, let’s see how this elevated permissions could be set.

In order to request elevated permissions while installing the out-of-browser application, the ApplicationManifest.xaml should has following section:

  <OutOfBrowserSettings.SecuritySettings>
    <SecuritySettings ElevatedPermissions="Required" />
  </OutOfBrowserSettings.SecuritySettings>

This section could be set by direct editing of OutOfBrowserSettings.xml in project or by selecting a relevat checkbox in updated  “Out-of-Browser Settings” window in project properties.

image

At the runtime, while installing the application the user will get following prompt:

image

instead of non-elevated one:

image

If user will allow to install the application, at the runtime the presence (or absence) of elevated permissions could be checked:

if (App.Current.IsRunningOutOfBrowser && App.Current.HasElevatedPermissions)
{
  //...
}

To demonstrate some of functionalities of elevated OOB application I’ve created sample project. It is pretty simple:

image

COM Interop

Now let’s see how to use COM interop from Silverlight. In order to show the usage it, I’ll show how to export some data to Excel, will create the chart, and copy this chart to Word document. Also, I’ll use new keyword in C# 4.0 – dynamic.

In my sample application I have sample class “SalesPerson”, which holds data for salesmen, and “SalesReport” class, which has a bunch of “SalesPersons”:

public class SalesPerson
{
  public string Name { get; set; }
  public double GrossSales { get; set; }

  public SalesPerson(string name, double grossSales)
  {
    Name = name;
    GrossSales = grossSales;
  }
}

public class SalesReport : ObservableCollection<SalesPerson>
{ }

Also I have some code to initialize the collection of salespersons… Now let’s see how to export this data to excel – I’ll do it at “COM Interop” button event handler.

First we need to check, that application is running Out-of-Browser, has elevated permissions and COM automation is operational on the current platform or at a certain point in the life of the application:

private void btnInterop_Click(object sender, RoutedEventArgs e)
{
  if (App.Current.IsRunningOutOfBrowser && App.Current.HasElevatedPermissions)
  {
    if (ComAutomationFactory.IsAvailable)
    {
      //...
    }
  }
}

Now the COM interop stuff: I’ll use new feature in C# 4 – the dynamic keyword. Little bit about dynamic keyword (from the documentation):

The dynamic type enables the operations in which it occurs to bypass compile-time type checking. Instead, these operations are resolved at run time. The type simplifies access to COM APIs such as the Office Automation APIs, and also to dynamic APIs such as IronPython libraries, and to the HTML Document Object Model (DOM).

Type dynamic behaves like type object in most circumstances. However, operations that contain expressions of type dynamic are not resolved or type checked by the compiler. The compiler packages together information about the operation, and that information is later used to evaluate the operation at run time. As part of the process, variables of type dynamic are compiled into variables of type object. Therefore, type dynamic exists only at compile time, not at run time.

I’ll use the dynamic to create the instance or Excel and Word applications and operate them. Inside the function body:

dynamic excel = ComAutomationFactory.CreateObject("Excel.Application");

excel.Visible = true;
excel.Workbooks.Add();
excel.Cells[1, 1] = "Salesperson Name";
excel.Cells[1, 2] = "Gross Sales";

//Initialize dummy data
SalesReport sales = new SalesReport();
InitializeSalesData(sales);

//convert/prepare dummy data for excel
string[,] processes = InitializeExcelData(sales);

int i = 2;
for (int j = 0; j < processes.GetLength(0); j++)
{
     excel.Cells[i, 1] = processes[j, 0];
     excel.Cells[i, 2] = processes[j, 1];
     i++;
}
dynamic range = excel.Cells[1, 1];
dynamic chart = excel.ActiveWorkbook.Charts.Add(After: excel.ActiveSheet); //Optional parameter
chart.ChartStyle = 45; //Bar chart - in therop this represented by enum
chart.CopyPicture(1, 2, 1); //parameters here are enum values - see documentation for CopyPicture parameters

I’ve started a new instance of Excel, created a new workbook, added my data to the cells of this workbook. At the end of this part I’ve created a new bar chart and copied it to clipboard. In the chart object creation I’ve used another new feature of C# 4 – optional parameter. See the “Add” function call.

Now I will create the instance of Word application with a new document and will paste prepared chart to this document

dynamic word = ComAutomationFactory.CreateObject("Word.Application");
word.Documents.Add();
word.Selection.Paste();
word.Visible = true;

At the end of this operation we have Excel and Word opened with data and bar chart. From here we could save/print the workbook/document using same automation mechanisms to automate office applications.

 

HTML Hosting

Additional functionality available for elevated OOB application is HTML hosting. This functionality being exposed by WebBrowser user control (new in Silverlight 4). This control allow to navigate to HTML string or any URI. In non-OOB application or non-elevated OOB the control has following UI:

image

But in elevated OOB application it able to render any HTML page (including applications which requires additional plug-ins to work, like Silverlight or Flash):

image
Pure HTML application

image
HTML with Silverlight application.

In my case I’ll use “HTML Hosting” button event handler to navigate. As input I’m using TextBox named “txtURL” (the one with blue background on the screenshots):

browser.Navigate(new Uri(txtURL.Text));

In addition to WebBrowser control, Silverlight 4 provides HTMLBrush – the new brush class, which enables painting any UI element with the content rendered by WebBrowser control. I’ll use it to paint the rectangle:

image

HtmlBrush brush = new HtmlBrush();
brush.SetSource(browser);
brush.Stretch = Stretch.Uniform;
rectToFill.Fill = brush;

Applied as a brush to the rectangle:

image

 

Sample code (along with an additional sample code from next part) is here.

 

Stay tuned for next part – Notification Windows

Alex

Silverlight 4: New features overview (Part 2) – Printing Support

In previous part (here) I’ve created sample application which uses Webcam and captures the image.

In this post I’ll show how to print received image (and any part of the UI) to a printer.

In Silverlight 4 we got new class, called PrintDocument which is a part of “System.Windows.Printing” namespace.

This class provides a number of events, which helps to control the printing job:

  • StartPrint – occurs right after printer selection dialog successfully returns, prior the first page print
  • PrintPage – occurs when page is printing. Allows to control what will be printout on the page, size of printed area and addition printable pages
  • EndPrint – occurs after the printing operation complete (even if user cancel printing job)

In addition it exposes DocumentName property, in order to identify the document between printer jobs.

In my sample application I added a “Print” button, and will print 2 pages – one with the webcam image (the rectangle) and one with the buttons stack panel.

Updated application’s UI:

image

Now the interesting part – the “Print” button handler function:

int PageNumber = 0;
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
  PrintDocument pd = new PrintDocument();
  
  pd.PrintPage += (s, args) =>
    {
      if (PageNumber == 0) //If first page – print the rectangle
      {
        args.HasMorePages = true;
        args.PageVisual = rectFill;
        args.PrintableArea = new Size(rectFill.ActualWidth, rectFill.ActualHeight);
        PageNumber++;
      }
      else //Otherwise – print the stack panel contents
      {
        args.HasMorePages = false;
        args.PageVisual = stkButtons;
        args.PrintableArea = stkButtons.RenderSize;
      }
    };

  pd.StartPrint += (s, args) =>
    {
      //Prepare for first page print here...
    };

  pd.EndPrint += (s, args) =>
    {
      //Handle possilbe print errors here...
    };

  pd.DocumentName = "Silverlight 4 Test Document"; //This is optional, but helps to identify the print job
  pd.Print(); //Start printout
}

While printing the printer queue shows the document:

image

This way any UIElement could be printed to any installed printer. I’ve printed the document to XPS printer driver, so resulting XPS document has to pages:

image

Updated sample here.

Next time I’ll show how to take this application out of browser, elevate the permissions and use COM automation.

 

Stay tuned,

Alex

Silverlight 4: New features overview (Part 1) – Webcam/Mic Support

This post starts a series of post about new features in Silverlight 4 Beta released at PDC 09.

Today I’ll show how to use Webcam/Mic support feature in the new version.

In order to use the Webcam/Mic the user should has valid drivers installed. To see which from installed drivers could be used open Silverlight Configuration and select 4th tab:

image

This tab also allows to select default webcam/mic to use with Silverlight applications.

Webcam/Mic controlled by CaptureSource class. This class allows to select which capture device to use (Video and Audio) and controls capturing.

In order to demonstrate the API I’ve created sample applciation. It will looks like follows:

image

Let’s see how to operate “Webcam On” button…

I’ve created class variable:

CaptureSource cs;

 

This variable will be used also for the second button handler, that’s why I’ve created it in class level.

In handler function, in order to use webcam/mic we have to get the end-user permission:

if (CaptureDeviceConfiguration.AllowedDeviceAccess ||
         CaptureDeviceConfiguration.RequestDeviceAccess())
{
...
}

Those lines in runtime will render the standard Silverlight dialog box with a request to use webcam/mic. If user approves the request we will be able to use those devices:

image

In my sample I’ll use default video device, and will set it as a video capture source for my capture sources:

VideoCaptureDevice vcd = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
//AudioCaptureDevice acd = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice(); //Could use it, but not needed heere
if (null != vcd /*&& null != acd*/)
{
   cs = new CaptureSource();
   cs.VideoCaptureDevice = vcd;
   //cs.AudioCaptureDevice = acd;
...

When everything is set I’ll start capturing.

cs.Start();

I’ll use the capture source as a source for the videobrush, and will paint with it the rectangle:

VideoBrush videoBrush = new VideoBrush();
videoBrush.Stretch = Stretch.Uniform;
videoBrush.SetSource(cs);
rectFill.Fill = videoBrush;

When running the application it will capture the video from the webcam and display it on screen:

image

Now for the capture of image. The handler of the “Capture Me!” button will enable asynchronous capturing of the image, and after getting the captured image will popup ChildWindow. The received image will be as a source for an image on this popup.

Button handler:

cs.AsyncCaptureImage(GetImage);

The “GetImage” function body (ScreenCapture is a ChildWindow instance):

ScreenCapture sc = new ScreenCapture();
sc.img.Source = bitmap;
sc.Show();

The running application:

image

 

The source for this app here (need Visual Studio 2010 Beta 2 & SL4 Beta).

 

Next time I’ll show how to use new built-in print support to print the captured image.

 

Stay tuned,

Alex

Silverlight 4: What’s New?

Today Microsoft announced new version of Silverlight, and released the Beta version of Silverlight 4.

Here is the summary of new features in this version:

  • Better Out of Browser Applications
    • Elevated Privileges Support
      • Cross Domain Networking Access
      • Full file path from Open/SaveFileDialog
      • No User-Initiation Requirement for Full Screen, Open/SaveFileDialogs
      • COM interop
      • HTML Hosting Support
  • Media Enhancements
    • WMS Multicast Support
    • Mp4 Playback Protected by PlayReady DRM
    • Offline DRM
    • Output Protection
    • WebCam/Mic Support (raw stream only)
  • Printing Support
  • Text Features
    • RichTextBox
    • Arabic and Hebrew Text Support
    • IME Improvements for TextBox
    • UIElement.TextInput event
  • Controls, Control Model, Layout
    • Drop from outside of Silverlight support
    • Implicit Styles support
    • ViewBox in core
    • MouseWheel Support on ScrollViewer, TextBox, ComboBox, Calendar, DatePicker
    • RTL Layout via UIElement.FlowDirection property
    • VisualStateGroup.CurrentStateGroup property
    • Command Property on ButtonBase & Hyperlink
    • SelectedValue and SelectedValuePath Properties on Selector
  • Networking features
    • Memory Usage Fix During Progressive Downloads
    • Automatically Adding Referrer Header
    • Authentication Support on ClientHttpWebRequest
  • Tools Support
    • Dispatcher Support on the Tools Design Surface
  • DataBinding Improvements
    • DataBinding Support for DependencyObjects
    • IDataErrorInfo Support
    • StringFormat, TargetNullValue & FallBackValue Properties on Binding
    • ObservableCollection<T> constructor accepts INumerable or Ilist
    • IEditableCollectionView
    • Grouping support on CollectionViewSource
  • SDK
    • Astoria 2.0 Support
    • MEF
  • Other
    • Expose Runtime Version to 3rd Party DLLs
    • NGEN Support for Core Runtime Binaries

Posts about usage of those features to follow soon!

 

Stay tuned

 

Enjoy,

Alex

PDC09 – Day 2 – Keynotes – Live blogging

PDC09 – Day 2 – Keynotes – Live blogging

Like yesterday we are sitting in amazing place 8 row just in front of the stage creating a homorganic row of blue shirts (There is a power in numbers).

IMG_1379 IMG_1381

Even that this happened after an hour of the keynotes I need to put this first :

FREE LAPTOP !!!

Steven just Announced that we all going to get a FRESH NEW LAPTOP from Acer to all. The crowed just jumped out of their chairs for that. When we first come to the PDC we asked our self what will be the “Gift” this year, last year it was a external HD but this year MS come out and surprise us all.

 IMG_1402 IMG_1403

And now back to the keynotes

Steven Sinofsky from Microsoft just come on stage and starting talking about development for Windows7.

Microsoft learned a lot from development of Windows7 :

  • Solving the existing problems and add-on Innovation
  • Engineering 7” developers blog that was full with on going problems that the developers team encounter and very active dialog with the developers community from around the world.
  • Ecosystem readiness – Vista was pre-mature for the market, the HW wasn’t ready (Drivers and Performance)
  • Software Quality And Windows Error Reporting – Online reporting from problems during the Beta and RC, Helped the development and the readiness of the Eco-Systems – Note – I wish we could do something like that but I guess you need to be large enough to make people opt-in to this type of telemetry collecting.

As part of the learning progress Microsoft learned that most people don’t hold the latest and greatest computer hardware and all of the demos are shown in a variety of computers

Internet Explorer 9

as part of the commitment of MS to make sure that IE won’t set a standard (like IE6 did) but to comply with the world wide web standards a new release of IE9 comes :

  • Standards – HTML 5, ACID3
  • Performance – JavaScript improvements – IE9 is as fast as any other browser beta out in the field.
  • Round corners boarders for IE
  • Hardware assist rendering without change in the Website (Direct2D / Direct Write) this is amazing change that allow the web browser to take advantage of the hardware abilities that it runs on. The main change is again that NO CHANGES were done on the website.

Scott Guthrie

IMG_1405Silverlight, Silverlight, Silverlight, Silverlight, All of Silverlight 3 that was released 4 months ago with Expression Blend3 and Sketchflow.

Some demos displayed with sporting websites with DVR support and instant slow motions. IMG_1409Victoria Secret Fashion show is going to broadcast in Silverlight3 and so on the little sport event that called Winter Olympic

 

 

 

 

 

 

 

 

When Silverlight3 was announced on July 2009 Silverlight had an install base of 

IMG_1410

Today less than 5 months after Silverlight got

IMG_1411

 

 

Silverlight4

IMG_1412

Tons of new features in Silverlight4

 IMG_1413 IMG_1414

IMG_1415Accessing camera and microphone supporting your local hardware.

 

 

 

IMG_1416new pixelshader built in the engine

 

 

 

IMG_1417 new IIS Smooth Streaming – making sure that the amount of data streamed from the server to the browser is based on the real time state of the network and the client application.

Silverlight media experience on CodePlex.com

This is already supports iPhone and any other non natively supported browsers and devices.  just changing a single checkbox on the IIS admin applet.

Live Demo – Crash, Stott tried to display the new feature on iPhone and had to switch 4 devices before it worked (“please, please said Scott”)

Other Amazing New Feature and some of them are way overdue :

  1. Printing !!!
  2. Rich Text
  3. Clipboard Access, Selecting text from Data grid can work to Excel
  4. Right Click
  5. Mouse Wheel
  6. Implicit Styles
  7. Drag/Drop
  8. Bidi & RTL
  9. HTML hosting – Use the HTML content as brush to paint any Silverlight control
  10. Commanding MVVM
  11. New Controls
  12. Share Assemblies Across SL and .Net4
  13. UDP Multicast support
  14. REST Enhancements
  15. WCF Improvements – TCP Channel Support
  16. WCF RIS Services

Scott Hanselman

IMG_1424

Scott replace Scott and started showing off a live demo of the new RIA services and some off the new features of Silverlight4

Back to Scott

Scott Gu come back to stage and showed off some new feature like :

  1. Trusted Application – Running outside of the sandbox
  2. Accessing Windows API
  3. Microsoft Office interoperability 
  4. Performance - Twice as fast, 30% faster startup and New profiling support
  5. Still 10 second install process

Schedule

Beta – Now Available – Silverlight.net

Release – before Q2 2010

Conclusion

Today keynotes gave us a better feeling than yesterday, Maybe this is just me but this happen also last year with the Windows7 announcement.

We heading out to pick up our new Toy.

This was a Shared post by Alex Golesh and Noam Sheffer

PDC09 Day 1 – Sketch Flow

Live blogging…

Last session for today – and it is SketchFlow prototyping with Christian Schormann.

The session is good, with very nice demos. Chris talking about SketchFlow in a nutshell - dynamic, interactive prototypes.

For modern UX the static mockups are not enough anymore.

After short and nice introduction he’s getting to the demos. Describing how SketchFlow built. He is going build the Skateboard shopping application. At this point the session is getting to be pretty close to the SketchFlow session I’ve attended at MIX09.

Christian showing the process of building Sketched application, the SketchFlow player, the process of UI/UX design thru sketching the prototype application. Now talking about SketchFlow player features, collecting feedback with it, presenting animations and UI/UX ideas to the end user, etc. Nice stuff.

 

For me – this session is the best from my today’s list.

 

Those who want to learn in-depth more about prototyping with SketchFlow: at Sela, we have a course which talks exactly about it. Guess the author ;)

image

 

That’s it for today. Stay tuned for tomorrow’s keynotes with Scott Guthrie!

Alex

Posted by Alex Golesh | with no comments

PDC09 Day 1 – Dynamics in C# 4

Switched to the Dynamics in C# 4 session. This session hall is not full at all… I’d rather say it is pretty empty… Probably this session is for real technology geeks like me :)

 

Did you know, that you cold create your own dynamic object by deriving from DynamicObject base class?

class Program
{
  static void Main(string[] args)
  {
    dynamic d = new myDynamic();
    Console.WriteLine(d++);
  }
}

class myDynamic : DynamicObject
{
  public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
  {
    Console.WriteLine(binder.Operation);
    result = 25;
    return true;
  }
}

image

Nice :)

 

 

 

Stay tuned,

Alex

PDC09 Day 1 - Expression Blend Tips & Trick Session

Got to the Expression Blend 3 Tips and Trick session. Probably it’s me, but the tips & tricks are pretty known and straight forward… Don’t get me wrong – they perfectly fine, but for someone who never really used the tools or at least not using Expression Blend at daily basis.

 

Switching to original plans and going to C# 4 session.

 

Stay tuned,

Alex

Posted by Alex Golesh | with no comments
תגים:, , , ,

PDC09 – Day 1 – Keynotes with Ray Ozzie & Bob Muglia

 

I'm sitting on the 8th row in the center in-front of the stage with 3 other coworkers from Sela waiting for Ray Ozzie to come up and started talking about S+S and the flow of changes that come since talking about Windows Azure and Office Online / Services.

The main topic for today keynote is cloud computing and the connection of multi platforms like Desktop/Notebook/Phone/TV to the cloud and its services. Looking for seamless multi screen experiences that is based on the web connectivity.

Ray keep dropping hints for Windows Phone (used be Windows Mobile) and what to expect in MIX2010 around April 2010.

Ray talked about MS commitment to the browsers war, Still putting a lot of strength in pushing IE as the main platform with Silverlight for all platforms including Windows Phone

IMG_1348 IMG_1355

Next the CEO of Seesmic come to show the new version of their application which is based on Silverlight 3.0 speaking about the time they saved as small company by developing in Silverlight and Managed environment and by that dropping Adobe AIR platform and releasing today their full Silverlight version.

Azure Advances

Azure is maturing into production and as part of that all existing CTP programs are starting to close and would terminate by Jan-2010. Major part of this set is the introduction of the Azure Data Centers.

Data Centers

Azure data center is shifting from Beta to Release mode and currently there are 6 data center worldwide with 2 in North America, 2 In Europe and 2 the far east (Asia).

SQL Azure

SQL Azure is now fully evolved DB that allow the developer to use it as if he had an instance running localing on the machine with connection to Excel for example.
Another new feature is the ability to mount a BLOB data file as VHD to the virtual machine and using Windows Azure BLOB support.

WordPress

Automatic CEO that built the OpenSource WordPress framework come on stage to show up WordPress running under Windows Azure. Automatic transferred their backbone from Linux/PHP/Apache dedicate machines to Windows Azure environment running WordPress platform.
Fail blog owner come and showed how today they can handle a large peek in demand without the need to add new hardware to the backbone and receiving the performance just by changing the configuration file of the Azure site.

“Dallas”

Code name for data catalog with uniform discovering/exploring and using data This new codename is part of SQL Azure. This is a way for developers and companies to share and sell their data to other parties.

“Dallas” Data Explorer

Allow a developer to use and process the data without the need to understand the structure and start using it immediately. By using ADO.Net data services (a.k.a ASTORIA or now O.Data) allowing us to create a data proxy on the fly and add new data sources and export it directly to your application.

A very nice demo of accessing a public domain data from NASA, using the Mars Pathfinder 3rd pictures and creating a viewer application that digests that data with less than 15 rows of code.

Shared post by me and Noam Sheffer

 

This is it for first PDC Keynote…

 

Stay tuned,

Alex

PDC 09: Pre-First Day

Today is my first day for PDC09. Will try to attend the following sessions:

Keynote (for sure, couldn’t miss it)

Future directions of C# & VB

Expression Blend for Developers: Tips, Tricks and Best Practices (or Dynamic Binding in C# 4)

FREE SLOT

Windows Touch Deep Dive

SketchFlow: Prototyping to the Rescue (or Advanced WPF application performance tuning and analysis)

 

Promise to summarize my lectures :)

 

Those who want in PDC and want to meet in person – come to Sela Group booth (#413) at my free slot.

 

Stay tuned and see you there,

Alex

Posted by Alex Golesh | with no comments
תגים:, , ,

Silverlight Tip: Enumerating embedded resources

Today I’ve got a “Call for Help” from one of Silverlight MVPs – Bill Reiss. The mail said:

“I would like to enumerate all items that were marked as Content or Resource in the main XAP file.

If I can’t do both I’d settle for one. Any sample code for this would be greatly appreciated.

Bill”

 

I decided to help with embedded resources, because I did something like this in WPF.

I’ve created sample application, which will display a list of resources in list box – from here it is very easy to use them by name. My sample will load the resource as image.

For application I’ve added 3 sample images and marked them “Resource” in properties:

image

The application UI:

image

XAML for sample:

    <StackPanel x:Name="LayoutRoot" Background="White" Orientation="Vertical">
        <StackPanel Orientation="Horizontal" Margin="5">
            <Button Content="Embedded Resources" Padding="5" Margin="5" x:Name="btnEmbedded" Click="btnEmbedded_Click"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Margin="5">
            <StackPanel Orientation="Vertical" Margin="5">
                <TextBlock Text="Embedded Resources:" Margin="5,0"/>
                <ListBox x:Name="lstEmbedded" SelectionChanged="lstEmbedded_SelectionChanged" Margin="5"/>
                <Image x:Name="imgEmbedded" Stretch="Uniform" Width="150" Height="150" Margin="5,0"/>
            </StackPanel>
        </StackPanel>
    </StackPanel

At code behind I have 2 event handler functions. First – to handle button click and get the resources.

First of all I have to open XAP file as a resource:

WebClient wc = new WebClient();
wc.OpenReadCompleted += (s, args) =>
{
   if (args.Error == null)
   {
      //rest will be here
   }
};
wc.OpenReadAsync(new Uri("SL_Resources_Test.xap", UriKind.RelativeOrAbsolute));

When the OpenRead completes, first I have to get the list of assembly parts in XAP using application manifest.

XmlReader reader = XmlReader.Create(Application.GetResourceStream(new StreamResourceInfo(args.Result, null), 
new Uri("AppManifest.xaml", UriKind.Relative)).Stream); AssemblyPartCollection parts = new AssemblyPartCollection(); if (reader.Read()) { reader.ReadStartElement(); if (reader.ReadToNextSibling("Deployment.Parts")) { while (reader.ReadToFollowing("AssemblyPart")) { parts.Add(new AssemblyPart() { Source = reader.GetAttribute("Source") }); } } }

Now, when I have a list of all parts (DLLs which could have embedded resources) I will get resources from each one of the DLLs:

List<string> embeddedResources = new List<string>(); //Will use this list as source for ListBox later in code

foreach (var part in parts)
{
   Assembly assy = part.Load(Application.GetResourceStream(new StreamResourceInfo(args.Result, null), 
new Uri(part.Source, UriKind.Relative)).Stream); //Load current assembly string[] resources = assy.GetManifestResourceNames(); //Get embedded resource names foreach (var resource in resources) { ResourceManager rm = new ResourceManager(resource.Replace(".resources",""), assy); //All resources has “.resources” in the name – so I have to get rid of it Stream DUMMY = rm.GetStream("app.xaml"); //Seems like some issue here, but without getting any real stream next statement doesn't work.... ResourceSet rs = rm.GetResourceSet(Thread.CurrentThread.CurrentUICulture, false, true); //to get the actual values - create the table //Dictionary<string, object> table = new Dictionary<string, object>(); IDictionaryEnumerator enumerator = rs.GetEnumerator(); while (enumerator.MoveNext()) { embeddedResources.Add((string)enumerator.Key); //It is also possible to get the value and key instead of just key //object obj2 = enumerator.Value; //table.Add((string)enumerator.Key, obj2); } } } lstEmbedded.ItemsSource = embeddedResources; //Use prepared list as a source for ListBox

Now my embedded resources enumerated.

Second part – use the resource by name when selection changed in the list box:

private void lstEmbedded_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    Uri uri = new Uri(lstEmbedded.SelectedItem.ToString(), UriKind.RelativeOrAbsolute);

    BitmapImage img = new BitmapImage(uri);
    imgEmbedded.Source = img; 
}

 

Running application:

image

image image image

 

Sample source here.

 

Stay tuned for more posts and news to come from PDC09.

 

 

See you at PDC09 and SDP!

Alex

More Posts Next page »