Search
More About This Website

All information is provided "AS IS" with no warranties, and confers no rights

Login
Wednesday
Nov182009

New Silverlight 4 Book Content

Today we are happy to be able to announce the availability of some Silverlight 4 book content. For existing Silverlight developers looking to get up to speed quickly with the features we are releasing the Silverlight 4 Overview. This is a little over 50 pages of content covering the new Silverlight 4 features.  For the rest of this week using code SL4DaveBlog at checkout you can get the new Silverlight 4 content for only $5 almost half off the normal price.  More details on the book site http://www.silverlightjumpstart.com

For developers that are new to Silverlight but are comfortable with .NET we are releasing a preview of Silverlight 4 Jumpstart. Silverlight 4 Jumpstart content builds on the success of the Silverlight 3 Jumpstart book to offer content focused at the business .NET developer.

Both of these offerings are available today and will continue to evolve with the Silverlight 4 release. These are delivered in an electronic format (PDF) and will continue to be updated with more current releases of Silverlight 4.

 

The following is an excerpt from the Silverlight 4 Overview chapter that is available as part of Silverlight 4 Jumpstart Preview book or as a standalone chapter from SilverlightJumpstart.com. The full overview chapter covers all the major new features of Silverlight 4 to help you get up to speed quickly.

Microsoft has fast tracked Silverlight to be a strong competitor in the global RIA space and squarely positioned itself against competitors like Adobe, Google and Yahoo for production of the finest RIA toolset. The initial battleground was video, but we are now seeing Silverlight has strong potential for building business applications as well. We have tried through the previous chapters to streamline your learning of the current version of Silverlight by focusing on the key areas a business developer needs to know. Now it’s time to talk about the future and what the road ahead looks like for Silverlight.

It had only been about nine months since Silverlight 2 was released in October 2008 that Silverlight 3 hit the street in July 2009. Then, just four months after the release of Silverlight 3 Microsoft released Silverlight 4 Beta at its Professional Developer Conference in November 2009. Each of these releases build on the prior one to add new features while at the same time keeping compatibility to support this fast pace of innovation.

If I had to pick a single theme for the main items that are part of Silverlight 4 I would have to choose “You Asked, Microsoft built it”. I say that because many of the items like Printing or Web Camera/Microphone support for example were some of the highest user prioritized features. You can check that out for yourself at Silverlight.UserVoice.com and while you’re there add or vote on a couple of your requests.

Silverlight 4 is also a major deal because it’s the first release of Silverlight to support .NET 4 CLR (Common Language Runtime). This gives developers access to the latest runtime features that are added to CLR4 including things like dynamic object support.

In addition to the core Silverlight 4 Beta, Microsoft also released corresponding updates to the other tools and products used with Silverlight. The tools for working with Silverlight from within Visual Studio were updated to support the Silverlight 4 Beta. This includes increased designer support to make it easier to develop Silverlight applications without having to leave Visual Studio for a separate tool. A new version of the Silverlight Toolkit was also released that goes along with the Silverlight 4 update. An update was also released for .NET RIA Services which has now been renamed as WCF RIA Services to reflect the fact that it now rides on top of WCF. This is an evolution of the prior .NET RIA Services releases and positions it to leverage WCF as a foundation to build on going forward. In addition to the WCF change a number of additional features such as improved inheritance support were added to WCF RIA Services in this release. Finally, a preview release of Blend for .NET 4 was released to allow it to work with Silverlight 4.
In the rest of this chapter we are going to preview some of these features that you will see in the Silverlight 4 Beta release.

Web Camera / Microphone Support

Silverlight 4 now allows developers to access to the raw audio and video streams on the local machine from applications running both in and out of the browser. Using these capabilities developers can write applications including capture and collaboration using audio and video. This is built-in to the core runtime and no other special downloads are required on each machine. When the audio or video is accessed for the first time by the application the user will be prompted to approve the request. This ensures that audio and video is never accessed without the user’s knowledge preventing applications that capture silently in the background. The following is an example of the prompt the user sees when the application requests access to the devices.

VideoAudoPrompt

You will notice in the above image the site name is displayed. This is another safeguard to ensure the user knows which site is requesting access to the devices. Access is granted to just this application and only for this session of the application. Currently there is no option to persist the user’s approval to avoid re-prompting each time the application is run. Additionally, it’s all or nothing; you don’t get to choose video or microphone. It’s a combined approval.

Users with multiple devices can select the devices they want to be the default devices using the properties on the Silverlight plug-in. This can be selected by right-clicking on a Silverlight application and going to the Webcam/Mic tab.

The following is an example of what you will see on that tab.choosedefaultmic

Developers can get access to the chosen devices using the CaptureDeviceConfiguration class. Using this class you can call the GetDefaultAudioCaptureDevice or GetDefaultVideoCaptureDevice methods to retrieve the users selected defaults. The class also has GetAvailableAudioCaptureDevices and GetAvailableVideoCaptureDevices methods that allow you to enumerate the available devices if you want more control of choosing a device besides the default.

Prior to using the devices you must request access to the device by calling the RequestDeviceAccess() method from the CaptureDeviceConfiguration class. When this method is called it is responsible for showing the user approval dialog we saw earlier. This method must be called from a user initiated event handler like the event handler for a button click event. If you call it at other times it will either not do anything or produce an error. Using the AllowedDeviceAccess property you can query if access has already been granted to the device.

The quickest way to get started using the video is to attach the capture from the device to a VideoBrush and then use the brush to paint the background of a border. The following XAML sets up the button to trigger the capture and a border that we will paint with a video brush.

<StackPanel>

<Button x:Name="btnStartvideo" Click="btnStartvideo_Click"

Content="Start Video"></Button>

<Border x:Name="borderVideo" Height="200" Width="200"></Border>

</StackPanel>

Next, the following private method TurnOnVideo method is called from the handler for the click event on the button. This satisfies the requirement to be user initiated.

private void TurnOnVideo()

{

VideoCaptureDevice videoCap =

CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

AudioCaptureDevice audioCap =

CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();

CaptureSource capsource = new CaptureSource();

capsource.AudioCaptureDevice = audioCap;

capsource.VideoCaptureDevice = videoCap;

if (CaptureDeviceConfiguration.AllowedDeviceAccess

|| CaptureDeviceConfiguration.RequestDeviceAccess())

{

capsource.Start();

VideoBrush vidBrush = new VideoBrush();

vidBrush.SetSource(capsource);

borderVideo.Background = vidBrush;

}

}

As you can see in the code above, default audio and video devices are retrieved and assigned to a CaptureSource. Access to the devices is then checked and requested if not already approved.

If access is granted the Start() method on the CaptureSource is invoked to begin capturing audio and video. Finally, the VideoBrush source is set to the CaptureSource instance and the background on the border is set to the VideoBrush.

Overtime we will probably see some very interesting applications of the audio and video support. One example that we put together was using it with Microsoft Dynamics CRM. In this example application a membership application was simulated that associated members with pictures and stored the pictures in a database. Think of a place similar to Costco, Sam’s Club or your local gym that snaps your photo for their records.

In the following image you can see how a tab has been added to the Contact form using the CRM customization capabilities.

 

CRMCap1

A Silverlight 4 application is then hosted inside that tab that will provide the user experience for capturing the images. When the Start Camera button is clicked the user will be prompted to approve the access and the video feed will begin as you can see below.

crmcap3

The video feed will keep showing the live image updated from the web cam until stopped. The Capture button on the above application allows the user to capture one of the image frames from the capture source. The AsyncCaptureImage(..) method on the CaptureSource class allows you to request that a frame be captured and your callback invoked. The callback is then invoked and passed a WriteableBitmap representing the captured frame.

crmcap4

This image can then be saved back to the Dynamics CRM server and associated with the record being viewed.

In the above example we looked at how you could use the video capabilities to capture a static image. More advanced applications are also possible for things like collaboration by showing the real time audio and video feed of multiple users.

You have been reading about one of the many new and exciting features of Silverlight 4 that are covered in the complete overview chapter. Visit SilverlightJumpstart.com today to access the full chapter.

Sunday
Oct112009

Cloud Computing Meets the Tax Man

Friday I got a nice surprise e-mail from the Azure team - “Action Required : Migrating Applications from the “USA – Northwest” – it continued to let me know that the northwest region will no longer be supported.  It suggested that I delete my project and re-create it using the south west region.  Ideally I would prefer they just handle it, but since Azure is still in CTP mode I will cut them a little slack. 

Looking into this a little more I found some more clear details on the Azure team blog here.  It explains “Due to a change in local tax laws, we’ve decided to migrate Windows Azure applications out of our northwest data center“  

You might notice the blog post is dated August – not sure if I saw that and thought it didn’t apply or never read it.  Either way, from my perspective most the time I don’t care if my data is in the South / North, East, West  - I do tend to care which country it’s in but besides that I just want it to be handled behind the scenes.  There are however good reasons to allow some control over the specific location when the application and / or business needs dictate.  It would be great to see Azure provide some tools to allow you to migrate data as needed between the regions.

As more applications move to have data hosted in the cloud we can only expect more skirmishes to occur with the taxing authorities as they wrestle to figure out a balance between getting their fair share of taxes and pushing businesses away.  This article on the Data Center Knowledge site elaborates a little more on the specifics of the Microsoft problem with Azure here.   I suspect we also haven’t seen the end of location matters for other legal jurisdictions of data as well but that’s a topic for another day.

Part of the appeal of cloud computing is it’s ability to abstract you from some of the low level issues of hosting data and computing power.  Power, cooling, hardware expenses, taxes and more are all of the package that makes this type of arrangement interesting.  It stands to reason that companies like Microsoft will make location decisions to where there is a strategic advantage for a key component of their expenses in providing the service.  In fact,  I think that will be required for any of these companies to be competitive.  I also think that making that as non impactful to the end user is also a core requirement of offering the service as well.

Wednesday
Sep232009

Lessons learned from my iPhone experiment

About once a year I need a new phone. Not because the old one dies, but I get bored and start looking for something new.  This year was no different as I approached my one year of replacing my Treo 750 with a Treo Pro I was in search of a new device.  For months, I had ignored everyone from friends to my Mom getting an iPhone.  Finally a few weeks ago about 15 minutes before the AT&T store closed I decided to grab one and give it a try. 

I lasted almost 3 weeks before I terminated the experiment due to a few different issues.  But before I did, I learned some interesting things.

I didn’t mind paying a small amount for useful apps – The under $3 applications make it so easy to not ponder too much about the decision to try it. The integrated application store is clearly what makes this so easy. I ponder, if micro transactions were easier all across the web would people be willing to part with their money more often?

Free applications are a powerful business tool – Just before walking into a restaurant the other night I made a reservation with Open Table’s application and just as we walked in it popped on the managers screen. News papers, Chipotle, Fandango there all there. Like the web made having a web page a requirement for a business the iPhone is having a similar effect in the mobile world. Today it’s the iPhone, but I suspect that’s just the catalyst that is helping people get comfortable with that type of interaction.

Not all phones have signal equality - It’s not new that different phones will have different reception patterns but I have never seen a phone in this price range be so inferior. Last weekend we had a chance to drive from Colorado to Utah. On multiple occasions my iPhone was the only AT&T phone in the car that was without signal. I travel a fair amount, and I have always enjoyed the fact that I arrive and my phone just works. I’ve had my other phones work on a boat, in remote areas and in other countries and never had I noticed such a difference to other AT&T phones as I have with the iPhone.

AT&T has a mini monopoly - I can only imagine the executive meeting where they decided to stick it to customers that wanted to jump on the iPhone parade. I knew about the data plan requirements, I was used to that. I also knew that they didn’t allow tethering. But I didn’t know that the international data plan I was paying $60 a month for jumped to $150 for no other reason than I had an iPhone. This is one aspect of the iPhone I won’t miss and it’s clear AT&T is milking every $ they can from the early iPhone adopters.

Google maps tracking was very jerky – Visiting a number of cities I don’t know well I became a big fan of the Windows Live search application and using the Track GPS feature that would follow you on a map and give you close to real time navigation. The only quirk I found on my Treo Pro with this was it was sometimes slow to acquire the GPS signal. iPhone has the Google maps application that is ok, but in practice I found it to be very jerky when it was trying to track your progress. So much so if you tried to use it for navigation you might not know you passed a turn.

Apple’s figured out application interaction – Sometimes (when it was working) I would use the iPhone to clear stuff out of my e-mail inbox. With just a swipe of my finger I could quickly delete an e-mail, bring it up, using two fingers to make the text larger. The multi select and delete had to be one of my favorite features. I also really liked how you could easily resize e-mails and web pages it made the mobile device really feel usable.

Connected Everywhere? Not yet! – Apple may have great insight, but iPhone may be ahead of its time assuming that users will be connected everywhere. I was shocked on my first airplane trip when I started to delete a few e-mails only to get a cryptic error message saying it couldn’t move the message. It turns out that “offline” isn’t in apples vocabulary. I believe we will get there eventually, but today occasionally connected is still a necessity.

Physical Keyboard vs. More Screen Real Estate – This is a tough one for me, I really liked the large screen area the iPhone had. In fact today being back on my Treo Pro I kept thinking how small the screen space is because of the keyboard. That said, there’s nothing like the feel of real keys when typing a message no matter how short the message is. The iPhone soft keyboard grew on me and I got better at it, but it still felt really clumsy compared to a real keyboard. Also, the correction algorithms that try to suggest spelling and word completion are very poor on the iPhone compared to what I’m used to on my Treo. At the end of the day though, I would trade physical keyboard for more screen space.

What’s with only supporting one Exchange Account - This isn’t just an Apple thing, Windows Mobile does it too. It’s great that devices are starting to support multiple e-mail accounts but there needs to be support for multiple Exchange accounts as well. It’s clear that Exchange e-mail support was an afterthought for the iPhone. Beyond just the multiple account support, I found the error messages cryptic, and 3 or 4 times I had to completely reset my mail account to get things working again. This seemed a little better in the recent 3.1 upgrade but not much.

It was small but made a great reader - Having the larger screen I was able to use the iPhone for reading e-mail, RSS feeds, FaceBook, News Papers and books. In fact, I really liked the Amazon Kindle reader. While some like the non-back light of the Kindle, for me the iPhone or iTouch represents just the right size for a carry anywhere device for reading stuff.

So between the coverage issues, the e-mail issues and the outrageous international data pricing I decided I could live without for now. Don’t get me wrong, I really liked the phone, it seemed to make me more productive. But something about having to keep resetting my e-mail and sometimes it causing the phone to not take inbound calls got on my nerves. So for now I’m a free agent, on the roam for a new phone. Maybe one of the new Windows mobile phones releasing in October will be interesting or maybe I will go through withdrawals and live with the iPhone quirks – Stay tuned!

Thursday
Sep102009

RIA Services – Finding the InnerException

One of the challenges I’ve run into with using RIA services is that sometimes you get back a message saying check InnerException only to find it is null. 

 

In the following example, I had deleted some data and submitted changes.  I set a break point on the server side in the delete method so I knew that it’s getting called and ran ok.  Back on the client side I would see an exception when checking the results of the submit operation as you can see in the following example.  The catch is notice that the message tells me to check the InnerException which is null!

image

 

While I clearly believe this is a bug and have reported it, I wanted to share how I track down what the real error is.  The quickest path I have found is to override the PersistChangeSet method on the server DomainService.  As you can see in the following example all I do is capture the error and I can set a break point.  You can now quickly determine what the error is.  If you want, this is also where you could “fixup” the exception to pass back a more meaningful message.

 

Update: From Nikhil - He suggests overriding Submit which is a good sugestion, the idea is you need to catch the error server side in order to know the "why" so there's two places you can hook into if you want.

 

image

Monday
Aug242009

Kicking the tires on SQL Azure

Last week I got my token to activate my SQL Azure service and took a few minutes to take it for a test drive.  If you haven’t heard about SQL Azure it’s the re-launch of SQL Data Services (SDS).  SDS used to be a much more restrictive model that really didn’t have any hope for sharing code between a traditional SQL Server and the cloud.  At Mix09 it was announced that SDS was going to go through some major changes for the best and move towards allowing more fuller relational and a powerful subset of TSQL support.  Recently in July, SDS was renamed to SQL Azure to better align the name.

Like other Azure services once I got the token, I just went to the portal and there’s now a SQL Azure section – after registering my token it allowed me to create a SQL Azure Instance and then I proceeded to create a new database via the web interface – this all happened really fast and painless. Now with a new database, I set out to figure out how to connect using SQL Studio. From the portal you can get your connection information but there’s a few quirks with the CTP you have to deal with.  Zach owns blog post on using SQL Azure is the best place to start to figure out how to connect.  Like I said it’s a little quirky, and you have to be patient with the timeouts that kick you off if you leave it idle, but the fact that I can use SQL Studio to query the data in the cloud was a huge plus!

Next, I wanted to move some table definitions from my local SQL server to my SQL Azure database.  There’s not a copy /upload database option yet – lets hope that gets added but in the mean time I found a couple of things that worked.  First, I tried the create script from within SQL Studio.  Using that approach I copied it into my query window for the new database and gave it a try.  You have to tweak the SQL some because things like Using database isn’t supported in the CTP  There’s some other keywords that aren’t supported either I just kept deleting them till I got my table create to run!

After some experimenting I actually found using Red Gates compare was the best approach because it would script multiple tables at once and the SQL seemed to be cleaner for what SQL Azure wanted (cleaner, not perfect I still had to do some tweaking).  The way I tried this was to create another empty DB locally that I would do the compare against to create my script.  That also worked as I modified and made changes to the tables I would just do the compare to that local copy and run the change script (slightly tweaked) on both the local copy and my SQL Azure db.  Who knows, maybe Red Gate will come out with a version specifically for doing this as I bet they could get something out quicker than MS tweak SQL Studio.

The database I moved to SQL Azure had a few tables that supported an application that used Entity Framework.  This is the part where I emphasize the improvements between the prior SDS and SQL Azure.  I simply took my connection string, pointed it to the cloud  and I was off and running.  Now I’m not saying you will find SQL in the cloud a seamless transition for every application and clearly there are some inherit things that are different with SQL Azure that you need to learn.  But compared to the prior SDS, I’m impressed and like where we are heading.  After almost a week of running this small database in the cloud with an application I use daily, so far so good!

Speaking of learning, there’s a lot more info on the SQL Azure dev center on MSDN you can find that here.

Sunday
Aug162009

Windows 7 Upgrade or Repave?

That’s a decision many of you will be making in the future if you haven’t already.  I’ve done both already and have had success with both approaches.  I’m not sure there’s a single right answer to which choice you should make.  I can tell you from past experience I tend to favor the re-pave as there’s just something about having a fresh install.  On one of my machines, my main office computer, I decided to do the upgrade.  Why you ask?  It’s one I don’t put any beta software on and it’s the cleanest of all my computers. Yeah I have a few.

The upgrade was smooth, but not nearly as fast as a fresh install of the base Windows 7 OS.  I’m not a time person so I didn’t get the stop watch out and watch, but I’d say if your doing an upgrade it took about an hour and a half to finish.  I would advise if your doing an upgrade to set aside 3-4 hours just in case you hit some snags.  Since I have multiple computers,. I’m not as worried if the upgrade had problems because I would just use another one.  So if you only have one, take the time to get a good backup of your current system in case things go way wrong.

Installing from a bootable USB is the way to go if you ask me…. My laptops don’t have DVD drives because with 16, 32 and 64gb flash drives who needs a 4gb DVD that’s easily broken when you travel.  In fact before now the only reason I would carry my external DVD player around was to re-install should the world end while I’m traveling.  Now with Windows 7 , I used made a bootable USB using this utility here.  That will shave another pound off my travel bag!  So far this has worked great and flash drives offer such good read performance the installs just fly.  I’m not sure you can finish a cup of coffee anymore for the base Widows 7 installation.

So back to Upgrade vs. Re-Pave.  Upgrades nice because all your stuff is just there still.  After the upgrade finishes and the reboot is done you login and no more work is required.  In some ways I think this is like real estate – some people buy a house and paint the walls pink, and put up all kinds of wall paper.  They invest a lot of time making small tweaks to make it feel like home.  Other people, just leave the walls alone knowing if they ever sell it’s less work in the future.  For me, I don’t do a lot of those tweaks because I’m always re-installing.  So for people that do a lot of “wall painting” you might want to consider upgrading because you don’t have to re-do the tweaks.  So if you have a pretty clean PC with out any beta software or other odd stuff that you’ve installed – give upgrade a try – worse case you can always do a re-pave if you don’t like what you get!

So why just re-pave?  It’s like cars  some people will drive a car till it stops running, others will swap it out ever few years.  For a Windows install the same is true – some only rebuild when they get a new computer, others are constantly rebuilding.  For me,like the new car, I like the freshness that a new install has.  It’s a quick way to dump all the junk you no longer need.  I only install things I’m actively using so I end up with a streamlined install – no bloat you get when you upgrade and carry along those wonderful things you installed and only used once. 

If your doing a re-pave the actual install of Windows 7 plus Microsoft Office goes really quick.  Where things slow down is if your a developer getting Visual Studio 2008 and SQL 2008 all setup.  In fact, the slowest part is the service packs to both of those.  You have the actual Visual Studio 2008 SP1 that must install, then once those are installed expect almost 1Gb of follow on updates that come down through windows update.  Visual Studio SP1 I think takes almost 4 times as long as Windows (remember my disclaimer I don’t pay attention to time, but it sure seems like forever) to install.  I always recommend not doing a fresh install when you plan to go on the road soon because you will find that you trickle install things over the next few days.  Even when I make a list of things I use all the time sure enough I forget something stupid like Adobe PDF Reader.

Finally, you will notice the title wasn’t Windows 7 Upgrade, Repave or “Don’t bother looking at Windows 7” so you can assume my recommendation is to move to Windows 7 when it becomes available to you.  I’ve been running it on all but one of my machines during the beta and couldn’t be more happy.  As to my favorite feature?  The fact that when you hit “Sleep” it just sleeps, and when you open the lid on your laptop it just flashes on with out delay.

So what’s are you going to do upgrade or repave, or what did you do and how did it work?

Monday
Aug102009

Behavior to Control DataForm AutoGenerate

The DataForm like the DataGrid control by default has the ability to auto generate fields based on the public properties of the object bound it.  This is controlled by the AutoGenerateFields property which is set to true by default.  I think the most common use for this feature is building demo apps and prototyping.  In those types of uses you can usually overlook the fact that there are a few properties with fields generated that you would never show a user of a business application.  In the rest of this blog post I will walk you through how you can add more control using a Silverlight 3 Behavior.

You can now also have more control over field generation by adding attributes to the class that you are binding to using the Editable and Display attributes.  Editable allows you to mark the property to be treated as read only or generate a one way binding.  Display as used below sets the AutoGenerateField property to false to ensure that the Age property doesn’t generate a UI Element.

image

You might have done similar things during the Silverlight 3 beta using the Bindable attribute which was replaced by using Display and Editable – see the change doc for more details. 

If you are using .NET RIA Services it helps by projecting attributes you place on the server side class metadata to the Silverlight client code generated.  When binding a class projected to the client by RIA services no extra work is required because these attributes are there.

These attributes help a lot and make it so there are even more places where the DataForm can be used.  One of the problems though is there are times where either you don’t want to mess with meta data, don’t have control over the class to add meta data, want a different set of fields included or excluded for a particular use.  In any of those cases probably the most common suggested work around is setting the AutoGenerateFields to false and specify a specific list of fields.  That can get real tedious real quick especially if you just wanted to hide a couple of fields.

The DataForm provides a useful event to help out here it’s called AutoGeneratingField.  This event is called as the DataForm is about to generate a field for a property.  In the event arguments you are passed the property name, the property type, a Field property and finally a Cancel flag.  The Field property is used if you want to provide a DataField back based on your own evaluation of the property name or type.  The Cancel flag though is what were most interested in for this blog post because it allows you to cancel generation of a field.  Using an event handler on that event you could accomplish the same thing we did with the attribute above as you can see in the following example.

image

While that’s helpful, I was really hoping for a way to package it up to be a little more reusable.  One way you could do that is inherit your own MyDataForm class from DataForm and override the OnAutoGenerateField method as you can see in the following example.

image 

I’ve of course over simplified this a little but you get the point.  I basically have a property that can pass in the fields I want and if not in the list I cancel the generation.  I would probably also include an ExcludeFields property as well so you could stop one or two fields from generating.  Both can be useful in making the DataForm useful for more scenarios.  The problem with this approach is that you then have to always use the MyDataForm class to get the benefit.  In the next example we will look at how to use a Silverlight Behavior.

Behaviors and Triggers are a new feature that we gained with Silverlight 3 and are packaged as part of the blend SDK in the System.Windows.Interactivity assembly.  They are nice because they let you add capabilities to existing controls without having to inherit from the control. In the rest of this post we are going to build a behavior to allow us to filter the fields.  The first thing that needs to be done after we add a reference to the System.Windows.interactivity assembly is to create our class that inherits from Behavior as you see below.

image

You will notice that we specify DataForm as the control type for the behavior – this allows us to have a typed property AssociatedObject that is of type DataForm. 

What we want to do is hook into the AutoFieldGeneratingEvent like we did in the past examples.  Behaviors provide an OnAttached method that you can override and accomplish registering the event handler as you can see below.

image

In the event handler we basically use similar logic like we did in the prior example or more fancy if we want but the idea is for fields we want to not show we set the Cancel flag. 

Using the behavior is pretty easy the first thing you need to do is declare a namespace reference for the System.Windows.Interactivity and the library that contains the behavior class as you can see below.

image

Then on the DataForm control instance we can hook up our behavior by using the Interaction.Behaviors markup as you can see below.

image

Behaviors are cool because they can easily attach on to an existing control to add behavior that makes sense.  By attaching on they keep the core control from becoming bloated with features that only get used once and  a while.

If you think this might be useful to you, drop me an e-mail and I will shoot you over a copy of the code.

Page 1 ... 3 4 5 6 7 ... 32 Next 7 Entries »