Silverlight 3 and the Bindable Attribute

You may see a number of videos and sample code for Silverlight 3 that uses the Bindable  attribute to specifying editing features of an entity property when working with the Silverlight DataForm control. However, the Bindable attribute (as well as the System.ComponentModel assembly) were removed from Silverlight with the Silverlight 3 RTM.


Now, if you want to specify if an entity property you are binding to should be readonly, set its Editable attribute like this:


 


[

Editable(false)]
public DateTime BirthDate { get; set; }


If you want to specify that a user interface control should not be automatically generated for a particular entity property, set its Display attribute like this:


 


[

Display(AutoGenerateField=false)]
public int EmployeeID { get; set; }


Best Regards,
Kevin McNeish
Chief Architect, MM .NET Application Framework
Oak Leaf Enterprises, Inc.
www.oakleafsd.com

Don’t Miss the Silverlight Toolkit for Getting Additional Silverlight Mojo!

Regardless of whether you have installed Silverlight for VS 2008 or VS2010, you will want to install the additional Silverlight Toolkit:


http://www.codeplex.com/Silverlight


This toolkit gives you additional controls, components and utilities released outside the regular Silverlight release cycle. This is good news because Microsoft is releasing new Silverlight functionality iteratively. Rather than providing these controls with a “big bang” release, Microsoft is releasing them iteratively to get feedback from the developer community (can anyone say “user stories”) before officially including them in the product.


These new controls are designated with different quality bands, indicating their level of maturity. This helps you decide whether you want to include them in your projects right now, or possibly wait until more mature versions of the controls are released. Here is a list of the four quality bands, listed in ascending order from least to most mature:


- Experimental
- Preview
- Stable
- Mature


Check out this link for a description of each quality level: http://silverlight.codeplex.com/wikipage?title=Quality%20Bands&referringTitle=Home.


This kind of iterative release is a good example for developers to follow. Software developers often have difficulty “letting go” of their code because they don’t want to put something in front of end uers that isn’t perfect, so they wait until they are finished to get feedback. The problem with this approach is that users can’t really provide solid feedback until they have something in front of them that they can play with. So, developers who wait until their software is complete before letting users provide feedback often find themselves rewriting and refactoring their code, and ultimately delaying the release of their software.


The moral is, get feedback as early and often as possible!

Best Regards,
Kevin McNeish
INETA Speaker
Chieft Architect, MM .NET Application Framework
www.oakleafsd.com


 

Pixel Shaders and Silverlight, WPF

Recently, Silverlight 3 gained the ability to use custom pixel shaders as was already available in WPF. What exactly are custom pixel shaders?


A shader is a set of software instructions executed on your computer’s Graphics Processing Unit (GPU) that performs complex per-pixel effects suh as applying a lighting value, bump mapping (a technique used to make a surface look more realistic by modeling interaction of a bumpy surface texture), shadows, highlights, translucency, and so on.


Pixel shaders are not a part of Silverlight or WPF, but are a technology used with DirectX. You define pixel shaders using a programming language called HLSL (High Level Shader Language), and this definition is stored in a text file with a .fx extension. You can create shaders using NVidia’s Shader Composer Tool (http://developer.nvidia.com/object/fx_composer_home.html)  or other similar tools.


Here is an example of a Negative effect:


sampler2D implicitInput : register(s0);

float4 PS(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(implicitInput, uv);
  
    float4 result; 
 
    result.r=1-color.r;
    result.g=1-color.g;
    result.b=1-color.b;
    result.a=color.a;
 
  
return result;
}


Note: You can add a text file to your project, give it a .fx extension and then past the above code into it. However, before this code can be compiled properly, you need to change its format to US ASCII. To do this:


- Select the .fx file in the Solution Explorer
- From the Visual Studio File menu, select Advanced Save Options…
- In the Encoding drop down, select US-ASCII


Setting up the Development Environment


Before you can use a pixel shader definition, you must compile the pixel shader .fx source code file into byte code stored in a .ps file. To do this, you need to install the DirectX SDK on  your computer (http://www.microsoft.com/downloads/details.aspx?FamilyID=24a541d6-0486-4453-8641-1eee9e21b282&displaylang=en).


The DirectX SDK has a shader compiler called fxc.exe. By default, it’s stored in the following folder on your computer (the month changes as new versions are released):


C:\Program Files\Microsoft DirectX SDK (November 2008)\Utilities\bin\x86\fxc.exe


You need to set up Visual Studio so it knows how to use the fxc.exe tool. To do this:


- In the Visual Studio Tools menu, select External Tools which launches the External Tools dialog.
- Click the Add button, and enter the following information:

        – Title: Microsoft &Shade Compiler (fxc.exe)
        – Command:  C:\Program Files\Microsoft DirectX SDK (November 2008)\Utilities\bin\x86\fxc.exe
        – Arguments: /DWPF /Od /T ps_2_0 /E $(ItemFileName)PS /Fo$(ProjectDir)$(ItemFileName).ps $(ItemPath)
        – InstallDirectory:  $TargetDir

- Select the Use Output Window checkbox, then click OK to add the new external tool entry


Now to run the compiler against a .fx file, select the .fx file in the Solution Explorer, then go to the Tools menu and select Microsoft Shader Compiler (fcx.exe). In the Visual Studio Output Window, you should see a “compilation succeeded” message, and the compiler should produce a .ps file with the same stem name as the .fx file. You should include this new file in your project, then set its Build Action property to Resource.


In order to use the new compiled shader effect, you need to create a ShaderEffect class. that loads the pixel shader. First, in your WPF or Silverlight project, you create a subclass of the .NET Framework’s ShaderEffect class.  Here’s an example:


 

 

public class SwirlEffect :

ShaderEffect

{

 

 

private static PixelShader _pixelShader = new PixelShader()

{

UriSource =

 

new Uri(“MyVideoProject;component/Swirl.ps”,

 

 

UriKind.Relative)

};

 

 

public SwirlEffect()

{

PixelShader = _pixelShader;

UpdateShaderValue(InputProperty);

UpdateShaderValue(FactorProperty);

}

 

 

public static readonly DependencyProperty InputProperty =

 

 

ShaderEffect.RegisterPixelShaderSamplerProperty(“Input”, typeof(SwirlEffect), 0);

 

 

public Brush Input

{

 

 

get { return (Brush)GetValue(InputProperty); }

 

 

set { SetValue(InputProperty, value); }

}

 

 

public static readonly DependencyProperty FactorProperty =

 

 

DependencyProperty.Register(“Factor”,

 

 

typeof(double), typeof(SwirlEffect),

 

 

new PropertyMetadata(0.0, PixelShaderConstantCallback(0)));

 

 

public double Factor

{

 

 

get { return (double)GetValue(FactorProperty); }

 

 

set { SetValue(FactorProperty, value); }

}

 

 

 

Best Regards,
Kevin McNeish
INETA Speaker
Chief Architect, MM .NET Application Framework
www.oakleafsd.com


Handling Trailing Spaces with VFP Data and ADO.NET

When working with Visual FoxPro data in ADO.NET, you may be surprised to see trailing spaces at the end of your character data. Visual FoxPro automatically trims these trailing spaces in BROWSE windows and when binding to user interface controls, but .NET does not.


To address this issue, you can change your character fields to varchar fields (introduced in VFP 9.0). You can then write a quick utility to remove the trailing spaces from the character data.


If you can’t remove the extra spaces due to requirements in your Visual FoxPro applications that are accessing the same data, you can remove the spaces programmatically in your .NET applications by adding RTRIM() commands to your ADO.NET SELECT statements. For example:


SELECT employeeid, lastname, RTRIM(firstname) as FirstName, title, titleofcourtesy, birthdate, hiredate, address, city, region, postalcode, country, homephone, extension, photo, notes, reportsto FROM Employees


Best Regards,
Kevin McNeish
Chief Architect MM .NET Application Framework
www.oakleafsd.com