Feed on
Posts
Comments

Get the best HLSL Book available for XAML developers

A comprehensive guide to creating HLSL pixel shaders for WPF and Silverlight applications

Really, this will be a must have book for hardcore xaml people. ... this is the best shader content I’ve seen to date. 
   
-- David Kelley

Dude this is great stuff!  A for interesting, A for correctness)!
  
--Jeremiah Morrill

I really like the chapter now, Really good content. :) 
   
--Rene Schulte

Reading the early release of @waltritscher 's HLSL for XAML developers book. Very good so far.
   -- Kris Athi

Learn more about shaders, get the book

HLSL and Pixel Shaders for XAML Developers


Synopsis:  The WPF/Silverlight TextBox control lacks the TextTrimming property. Use a control template to add TextTrimming to TextBox.

Want more Silverlight tips and tricks? Watch my Silverlight 5 Essential Training course

We’ve all encountered the textbox that is too narrow to hold the text contents.  Here’s an example from Visual Studio 2010

image

Figure 01: Visual Studio Dialog

The default behavior of the textbox is to truncate the text.  There is no visual feedback to the user that there is more text available, other than the textual context.  In other words, it is up to the user, to perceive that there is additional text that is not visible in the control

Text Trimming

One common solution, in UI circles, is to add ellipses (…) to the end of content shown in the text control.  In WPF and Silverlight 4 the TextBlock control has a TextTrimming property which handles this chore for you.

<TextBlock TextTrimming='CharacterEllipsis'
           Text='To Do:  Learn Win8 Metro'
           Width='98' />

Let’s look at a few examples.

image

Figure 02: Text controls with adequate room

 

image

Figure 03: Text controls with limited width

 

In Figure 02, the TextBox (A) and TextBlock  have plenty of room for the text.  In Figure 03, the text controls are too narrow.   As you can see the TextBlock (E) is showing the ellipses.

 

Fixing the TextBox control

The TextBox does not have the TextTrimming property.  In many situations, that is not a problem because you can use the TextWrapping property.   When a TextBox is limited to a narrow width, you can increase the control height, set  the VerticalScrollBarVisibility to Auto and enable TextWrapping. 

But there will be times when you are stuck with limited width and height for your TextBox.  In those scenarios, it would be nice to have TextTrimming available.

The solution below uses as control template.  When the TextBox has the focus, it’s a normal TextBox.  When it doesn’t have focus it is rendered as at TextBlock with TextTrimming enable.  The template also uses a Border around the TextBlock.  This keeps it looking like a TextBox when. I’ve also set the Background of the Border to a light gray color, to make it easier to see in the screen shots. 

 <Grid.Resources>
      <Style TargetType="TextBox"
             x:Key='TrimmingStyle'>
        <Style.Triggers>
          <DataTrigger Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource Self}}"
                       Value="false">
            <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                  <Border BorderThickness='1'
                          Background='#ffefefef'
                          BorderBrush='LightBlue'>
                    <TextBlock Text="{TemplateBinding Text}"
                               TextTrimming="CharacterEllipsis"
                               Margin='4,1' />
                  </Border>
                </ControlTemplate>
              </Setter.Value>
            </Setter>
          </DataTrigger>
        </Style.Triggers>
      </Style>

    </Grid.Resources>
...
 <TextBox Style='{StaticResource TrimmingStyle}'
           Width='297'
           Text='Pixel Shaders are one of the more powerful graphic tools ' />
<TextBox Style='{StaticResource TrimmingStyle}' 
          Width='297' 
          Text='Shader development is a very different from working in XAML' />

 

Screenshots

image

Figure 04:  Focus in the top TextBox

 

image

Figure 05:  Focus in the bottom TextBox.

 


LyndaSL5Banner

Want more Silverlight tips and tricks? 
Watch my Silverlight 5 Essential Training course.

AzureTrial-216x1003

 

This statistic, seemed unbelievable. Only one out of ten MSDN subscribers is using their free Azure benefits. According to Microsoft, MSDN subscribers get a boatload of free services each year (~$3700.00 USD)  I’m not talking about the free trial download.  This is something different.

If you have an MSDN subscription you get a lot of free Azure benefits.  For example, you get 30 GB of free storage on the Azure servers.  That’s a lot of MP3 files!

For data transfers, you get unlimited uploads, you only have to pay for download bandwidth.  Even so, you you get 35GB or download free every month before you have to start paying the piper.

Benefits are tied to your MSDN subscription level, the higher the level, the more you get.

Included each month at no charge (MSDN Ultimate)

  • Windows Azure
    • 1,500 hours of the Small Instance. 
    • 30 GB of storage
    • 4,000,000 storage transactions
    • 2,000,000 CDN transactions
  • SQL Azure
    • 5 GB web edition
  • Access Control, Service Bus and Caching
    • 128 MB cache
    • 500,000 Access Control transactions
  • Data Transfers
    • Free Inbound Data
  • 35GB Outbound Data
  • image

Download a free Azure trial and see if it helps in your scenarios.

According to major vendors like Amazon and Microsoft, the cloud is our future. No matter what type of application, it could benefit from cloud storage, cloud DB or cloud services. I believe there is a lot of truth in these ideals. But no technology is perfect for every scenario. That’s why its cool that you can try Microsoft Azure services for free.

AzureTrial-216x1003[3]

Did I mention that its free, that’s always a good price. [1]

Download your copy today and see if its useful for your scenarios.


 

[1]. OK, there are some limits. It’s a 90 day trial.

Visual Studio has a long history of supporting Code Snippets on the Toolbox.  You can drag a code chunk to the toolbox, and instantly have a reusable code resource.  So easy.

I’ve found that some XAML developers are not aware that this technique works with XAML blocks.  It does.  Select your XAML in the text editor and drag to toolbox.

image

Don’t like the auto-generated snippet name?  Right click the snippet and choose Rename Item, then  type in a new name.

image

In the future, just drag your snippet to the XAML window.

I’m working on some new course material for ASP.NET MVC 3. 

I have the need to take some of the ASP.NET special collection properties and turn them into a generic list.  For example, the Request.Cookies property is type as HttpCookieCollection which is based on the NameObjectCollectionBase type.

This snippet does the trick.

var cookieList = Request.Cookies.Cast<string>().ToList();

I’m not a fan of the Google Instant search feature.  Not a problem, as Google provides a way to disable the feature[1].  Except when it doesn’t work.

Instant search re-enables itself constantly, it’s like the undead rising over and over again.

Buckethead Zombie.png

Use this URL

I found that if I use this URL http://www.google.com/webhp?complete=0&hl=en I always get a Google search page with Instant search disabled.  But it also disables auto-suggest.  To eliminate just instant search use this URL. http://www.google.com/?ion=0 

That link is now in my bookmarks and part of my home page.

=====================================

[1]  The standard way to disable instant search is to open the Google search setting pages and choose "Never show instant results."

image

[2] Note: this disables the auto suggest on the search page, so it may not be the best solution for some.

[3] If you type fast on your keyboard, instant search often skips letters, which means you have to go back and retype.

[4] Yes, this is old news to some,  there are many threads on Google groups.  Mostly I blogged about this so I have a permanent record for my own use.

During a WPF class last week I was asked a lot of questions about ViewModels.  We were eating lunch, I was enjoying a smoky BBQ sandwich with all the fixings, when one of the guys at the table asked how to launch a webbrowser from the ViewModel. 

I had the code already, I’ve used it on a number of projects so when the class started again I showed this simple example.  Since I was already sharing the example with the students I thought I share my code.

I’m using the generic version of Josh Smiths  RelayCommand.

The BrowseToSiteCommand

private RelayCommand<string> _browseToSiteCommand;
   public RelayCommand<string> BrowseToSiteCommand {
     get {
       if (_browseToSiteCommand == null) {
         _browseToSiteCommand = new RelayCommand<string>((param) => BrowseToSite_Execute(param));
       }
       return _browseToSiteCommand;
     }
   }

   public void BrowseToSite_Execute(string url) {
     try {
       Process.Start(url);
     }
     catch {
      // error handling here…
     }

The bound MenuItem

<Grid Background="#101010"
        x:Name='mainGrid'
        DataContext='{StaticResource mainVM}'
        Effect='{Binding EntireWindowEffect}'>
. . . 
 
<MenuItem Header="HLSL and Pixel Shaders for XAML Developers - Book"
          Command='{Binding Path=BrowseToSiteCommand}'
          CommandParameter='http://shop.oreilly.com/product/0636920023869.do' />
 <MenuItem Header="Video Training"
           Command='{Binding Path=BrowseToSiteCommand}'
           CommandParameter='http://lynda.com/waltritscher' />

When you write for the O’Reilly animal book series you get a book cover with animal artwork.

For many years the most typical O’Reilly books, the "animal books," have been designed as thorough guides for work with established technologies. The original animal design was developed by Edie Freedman because she thought that Unix program names sounded like "weird animals."  -Wikipedia

The cover art work for my HLSL book.

I just got the PDF with my book cover.  Trey cool.

Now all it needs is a tagline for the top of the cover.  Got any ideas?

How about?

Bringing shaders to the managed world, one pixel at a time. 

or,

A comprehensive guide to creating HLSL Pixel shaders for WPF and Silverlight applications.

or,

Pixel shaders, not just for the game developer anymore

or,

Update

The publisher picked a tagline. I’ve update the picture.


HLSL Shader Book Coming soon

HLSL and Pixel Shaders for the XAML Developer. O’Reilly Media Inc..

http://shop.oreilly.com/product/0636920023869.do

It’s always entertaining to read other developers opinions when moving to new platforms and programming languages. Especially so, when one of the platforms they discuss is one that you have investigated yourself.  When they laud your favorite platform, you pat yourself on the back for being so astute in your platform choice.  When they nitpick the platform, you see the issues with fresh eyes.

Plex

Plex bridges the gap between your computer and your home theater, doing so with a visually appealing user interface that provides instant access to your media.

http://www.plexapp.com/

Elan is one of the developers on the Plex project.  They’ve just released their Windows phone 7 client.  Here are some juicy quotes from his blog post.

iPhone

Platforms face two ways, towards the users, and towards the developers. The iOS development environment is quite good, with the weakest link being Objective-C, which has a steep learning curve and feels like it stepped out of the 80s with a cocaine hangover.

Windows Phone 7

It’s scary good. C# is a great language, .NET is a solid framework, XAML is a really nice way to design user interfaces, and the edit-build-deploy cycle is fast. It still has a bit of growing up to do, but the proof, as they say, is in the pudding: we were able to write the app from start to finish in two months, between two engineers working part time, which is almost an order of magnitude faster than it took for the iOS and Android app.

Android

Android, oh, Android, I don’t mean to pick on you once again, but your edit-build-deploy cycle is long enough to make a grown man cry, and then stab himself in the eyeballs, and then cry some more. Java is fine, but the surrounding environment and piss-poor emulator makes it much harder to develop for than it should be.

http://elan.plexapp.com/2012/03/30/plex-for-windows-phone/

Develop your own Windows Phone apps

Get your own copy of the Windows Phone 7 SDK and try out the new Windows Phone programming tools yourself.

image

This is not breaking news by any means.  We all are aware of how hard it is to keep up with new tech coming out of the Redmond.

Here’s a few links to some of the more important APIs coming soon.  (feel free to speculate on Microsoft release dates.  At least download a copy and keep it handy.  Then when some free time comes along, you can install and start exploring.

 

WebMatrix-216x100

VisualStudio-216x100

Windowsphone-216x100

AzureTrial-216x100

Windows8-216x100

I’m using many of these APIs already,  I need to learn more about Azure though.  Maybe this summer, this Spring is crazy busy.

Older Posts »