Posts
17
Comments
3945
Trackbacks
21
febbraio 2006 Blog Posts
XamlMigrate
Rob Reylea has posted a XamlMigrate tool that helps migration of Xaml files to Feb CTP, really nice job!
posted @ domenica 26 febbraio 2006 18:33 | Feedback (144)
WinFX Feb CTP Available

WinFX Feb CTP has just been released.
No EID (Sparkle) available yet for this CTP but it will be soon :-)

Karsten has an interesting list of breaking changes.

posted @ mercoledì 22 febbraio 2006 22:07 | Feedback (78)
Upcoming XAML changes

Rob Reylea announces some changes that we're gonna find on next WPF CTP.
Apart renaming renaming of xml urins it looks like that we won't need PI instructions anymore for CLR mapping, really hope Cider will handle this better as it does now...
Happy to read that an upgrade tool will be available...

posted @ sabato 18 febbraio 2006 15:02 | Feedback (1004)
EID: Applying style using triggers

“In XAML you can define a style and have it applied based on an Event,Property or DataBinding property change.
To give you an idea, here's a XAML fragment that sets some properties of a button when mouse is over it.

<Style TargetType="{x:Type Button}">
  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
    <Setter Property="FontSize" Value="20" />
    <Setter Property="Foreground" Value="Red" />
  </Trigger>
 </Style.Triggers>
</Style>

To have the same result using EID (a.k.a “Sparkle”) you have to follow some steps.
Let's try, as demo, to have the background of a button changing when IsMouseOver property is true.

  • Start by drawing a button on scene's document root.
  • Right click and select to Edit a copy of the style (BTW: You can see the structure of original style on EID timeline)
  • Click on Timeline's Create new state button, you should now have a new [No Triggers] tab
  • On Timeline Properties Palette, press Add button and type IsMouseOver on left textbox and true on right one.
  • Now change the backcolor of the button, when finished press Return to scope root button.
  • Test the scene

You'll see backcolor change on MouseOver.
Editing is far than complete, I'm still not able to edit some properties (e.g. Opacity) and looks like that Event/DataBiding triggers are still work in progress, but you should have an idea of how thing should work.”

posted @ mercoledì 15 febbraio 2006 23:50 | Feedback (130)
Using BitmapEffects

“You can easily apply effects like Blur or DropShadows to a UI element using BitmapEffects property.

This xaml sample:

<Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="cor.jpg">
 <Image.BitmapEffect>
  <BitmapEffectGroup>
   <BitmapEffectGroup.Children>
    <BitmapEffectCollection>
      <BlurBitmapEffect Radius="2"/>
      <DropShadowBitmapEffect/>
    </BitmapEffectCollection>
   </BitmapEffectGroup.Children>
  </BitmapEffectGroup>
 </Image.BitmapEffect>
</Image> 
<TextBox Text="Hello WPF">
 <TextBox.BitmapEffect> 
  <BitmapEffectGroup>
    <BitmapEffectGroup.Children>
     <BitmapEffectCollection>
      <OuterGlowBitmapEffect GlowColor="Green" GlowSize="5" Noise="3"  />
      <DropShadowBitmapEffect/>
     </BitmapEffectCollection>
    </BitmapEffectGroup.Children>
  </BitmapEffectGroup> 
 </TextBox.BitmapEffect>
</TextBox>
Produces this effect:

As you can see various effects can be applied to the same element, just keep in mind that effects are processed in sequence so the order of appearance inside counts.”
Unfortunately Sparkle does not support direct editing of this property yet.

posted @ venerdì 10 febbraio 2006 18:52 | Feedback (1126)
Databinding using "Sparkle"

How to create a user interface that displays data from an external DataSource using Expression Interactive Designer (“Sparkle“)

  • Create a new Visual C# Library project named PersonsDataSource
  • Remove Class1 and add both Person and Persons class (described in my previous blog)
  • Compile project, you should now have a PersonsDataSource dll.
  • Open Sparkle and create a new Project (File ->New Project) name it as you like.
  • Now let's add a reference to our PersonsDataSource.dll using Project->Add Item to browse to the previously created assembly.
  • You'll now see the dll listed under Project references.
  • Open the Data Palette (View->Data) and select Add new CLR DataSource, browse to PersonsDataSource and select Persons item, you should now see Persons listed inside Data palette.
  • Select Persons item from Data palette and drag it to Document root surface
  • You'll be asked to select how the Persons datasource will be displayed, select ListBox and click Ok.
  • The Create Data Template appears: This dialog allows you to 'shape' the DataTemplate associated to Person object, you can select what items and what controls to map to various Person fields (in this case dialog defaults to TextBlocks) leave defaults and click Ok.
  • You'll should see the listbox filled with Persons items.
  • We now want to add 2 texboxes that will be populated with Listbox selected item.
  • Select Library palette and drag two textboxes on DocumentRoot surface.
  • Select first texbox and, on Properties palette, click on Text field and select DataBind...
  • You'll now see the Create Data Binding dialog, we need to bind to Listbox selected item so click on Element Property and select ListBox.
  • Select SelectedItem among ListBox properties.
  • Listbox contains instances of Person classes so, select Use custom path expression and type “SelectedItem.Name” (without quotes) on related textbox, then click Ok.
  • Do the same with other textbox using “SelectedItem.Age” as custom path expression.
  • Press F5 and you'll see that selecting a listbox item selection will be reflected on both textboxes and that changes on textbox contents will be moved to underlying DataSource.
posted @ venerdì 10 febbraio 2006 14:59 | Feedback (3605)
A little bit of WPF DataBinding...

Let's assume you wish to use DataBinding to manage a set of Person class instances.

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

 public class Person
 {
  public Person (string name, int age)
  {
   this.Name = name;
   this.Age = age;
  }

  private int mAge;
  public int Age
  {
   get { return mAge; }
   set { mAge = value; }
  }

  private string mName;
  public string Name
  {
   get { return mName; }
   set { mName = value; }
  }

  public override string ToString ()
  {
   return this.Name + " : " + this.Age.ToString();
  }

Now we create a Persons class inheriting from generic ObservableCollection

public class Persons:ObservableCollection<Person>
 {
  public Persons ()
  {
   base.Add(new Person("Corrado",22));
   base.Add(new Person("Giulia",1));
   base.Add(new Person("Stefania",10));
  }
 }


We now use ObjectDataSource to create Persons instance and have it available as DataContext inside xaml.

<?Mapping XmlNamespace="tds" ClrNamespace="Demo" ?>
<Window x:Class="Demo.Window1"
    xmlns="
http://schemas.microsoft.com/winfx/avalon/2005"
    xmlns:x="
http://schemas.microsoft.com/winfx/xaml/2005"
    xmlns:tds="tds"
    Title="Demo"
 >
 <Window.Resources>
  <ObjectDataProvider x:Key="Persons" ObjectType="{x:Type tds:Persons}"  />
  
  <DataTemplate DataType="{x:Type tds:Person}">
   <StackPanel Orientation="Horizontal">
    <TextBlock Foreground="Red" Text="{Binding Name}" FontSize="14" />
    <TextBlock Foreground="Blue" Text="{Binding Age}" FontSize="14"/>
   </StackPanel>
  </DataTemplate>  

 </Window.Resources>

<Grid>
   <ListBox ItemsSource="{Binding Source={StaticResource Persons}}" />    
</Grid>
</Window>
    
       
   
Red lines are namespace to Xml mapping instructions (syntax is probably going to be modified on next CTP)
Magenta line is the ObjectDataProvider definition that allows us to use Person list as datasource on the listbox.
Green lines indicates that both ObjectDataProvider and DataTemplate objects are part of Windows Resources.
DataTemplate (in blue) describes how the UI should display the Person instance (otherwise the ToString() method it will be invoked) in this case I decided to use a StackPanel containing two textblocks both binding to Person properties.
Data are databound to listbox by ItemSource attribute (in orange)
Datatemplates are required because on WPF ItemsControls (like ListBox) are not limited to strings but can contain virtually everything.

Just a simpe demo, but as you know, we all need a starting point... :-)

posted @ venerdì 10 febbraio 2006 00:34 | Feedback (54)
Borland leaves the IDE arena...
Looks like Borland is targeting new horizons... more here
posted @ giovedì 9 febbraio 2006 00:25 | Feedback (50)
A little help from Reflection...
Today a friend of mine asked me how to define enums containing white spaces, after my initial response (”Why the *** you want to do that?”) i ended up with this code that demonstrates how 'flexible' is .NET (in this case using VB but, as you know, language is just a detail...)

Created a custom attribute...

<AttributeUsage(AttributeTargets.Field)> _
Public NotInheritable Class EnumDisplay : Inherits
Attribute
Private mText As
String
Public Sub New(ByVal text As String
)
 mText = text
End
Sub
 Public ReadOnly Property Text() As
String
 Get
   
Return
mText
 End
Get
 End
Property
End
Class

...and a simple helper function that uses both Generics and Reflection...

Public Class EnumHelper
  Public Shared Function EnumToString(Of T As Structure)(ByVal value As T) As
String
  Dim sourceEnum As Type = value.GetType()
  Dim name As String = [Enum].GetName(sourceEnum, value)
  Dim fi As FieldInfo = sourceEnum.GetField(name)
  Dim att As EnumDisplay = TryCast(Attribute.GetCustomAttribute(fi, GetType(EnumDisplay)), EnumDisplay)
  If (att IsNot Nothing) Then Return att.Text
  Return name
  End
Function
End
Class

Now you can define your own Enum and decorate it with EnumDisplay where needed...

Public Enum TempState
 Low
 Middle
 <EnumDisplay("Hi Temperature"
)> HiTemperature
 TooHigh
End
Enum

And get a string representation of enum field using:

Console.WriteLine(EnumHelper.EnumToString(TempState.HiTemperature)) ' Hi Temperature

Cool!

posted @ mercoledì 8 febbraio 2006 23:47 | Feedback (41)
How to save custom types using Fx 2.0 settings

Here you can download a demo (VB & C#) that demonstrates how to save a custom type (in this case a Person Class) using Visual Studio 2005 settings, basically all you have to do is to associate the type with a custom TypeConverter so that settings engine is able to serialize your type inside user.config file.
More details on my
Italian blog

posted @ mercoledì 8 febbraio 2006 23:13 | Feedback (54)
HotFix for Windows Designer

If you, like many, suffer of Visual Studio 2005 designer crashed (often requiring you to restart VS) you'll be happy to know that a hotfix is now available (you have to query for it)
More details
here

 

posted @ mercoledì 8 febbraio 2006 23:06 | Feedback (920)
Application.OpenForms
I was playing with Application.OpenForms and gone lost figuring that it doesn't work if you try it with an unmodified Form (e.g. Form2), after a search on LadyBug discovered that it depends on the fact that Form's name is actually formalized only after you add some controls or specifically set it using Name property.
I'd love to have this behaviour reported on MSDN... :-(
posted @ mercoledì 8 febbraio 2006 23:04 | Feedback (124)
WPF - January CTP
It looks like that WPF January CTP is binary compatible with December CTP, so if you're not interested on WCF or WWF (that has changed a lot...) you can skip downloading. :-)
posted @ mercoledì 8 febbraio 2006 23:01 | Feedback (315)
News

This is my personal blog.
These postings are provided "AS IS" with no warranties, and confer no rights.

Disciple