Welcome to MSDN Blogs Sign in | Join | Help

Data binding is an extrememly cool avalon feature that lets you automatically populate UI with data.  Value converters supply a generic way to adapt a model to the view without having to write custom code.  For instance, it is fairly common to set visibility of elements based on whether or not they should be enabled, and you can data bind the visibility of your element to some bool property, and use a BoolToVisibilityConverter to convert the bool to a visibility.

But what if you want a more complex binding - what if you only want to show a listbox when the number of items is greater than zero?  Say you have an IntegerToBoolConverter, and a BoolToVisibilityConverter, but you don't want to write a new IntegerToVisibilityConverter.  If you add a composing converter to your value converter toolbox, you'll have a generic way to chain converters together.

public class ComposingConverter : IValueConverter
{
  private List<IValueConverter> converters = new List<IValueConverter>();
  public List<IValueConverter> Converters
  {
   get { return this.converters; }
  }

  public object Convert(object o, Type targetType, object parameter, CultureInfo culture)
  {
   for (int i = 0; i < this.converters.Count; i++)
   {
    o = converters[i].Convert(o, targetType, parameter, culture);
   }
   return o;
  }

  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  {
   for (int i = this.converters.Count - 1; i >= 0; i--)
   {
    value = converters[i].ConvertBack(value, targetType, parameter, culture);
   }
   return value;
  }
 }
}

Then you would use this converter like so:

<ComposingConverter>
 <ComposingConverter.Converters>
  <IntegerToBoolConverter/>
  <BoolToVisibilityConverter/>
 </ComposingConverter.Converters>
</ComposingConverter>

Focus scopes are a mechanism in avalon for allowing multiple elements to have focus simultaneously.  A very common example of multiple focus can be seen in Word - say you want to change the font size of a selection of text.  You select the text, then start typing in the font control to change the font size - and the application remembers that the text itself was selected.  If you built this kind of application in avalon without setting up focus scopes, the original textbox would lose focus when you started typing in the font size.

Here's a very simple example of a xaml layout with multiple focus scopes:

<StackPanel>
 <TextBox/>
 <TextBox FocusManager.IsFocusScope="True"/>
</StackPanel>

If you type some text into the first textbox, and select it, you can then give focus to the second text box without the original losing focus.  The avalon terminology is "logical" vs. "keyboard" focus - the original text box has logical focus, while the second text box would have keyboard focus. 

Also note that any elements that are in one focus scope won't lose logical focus if the keyboard focus changes to target an element in another focus scope.  In other words, every focus scope can have an element with logical focus, but only one element in the entire tree will have keyboard focus.

Since this is my first blog entry, I'll introduce myself.  I'm a developer at Microsoft working on Expression Interactive Designer.  I'll be using this blog to talk about Expression, Microsoft, and software development in general.  In other words, it will be very work oriented.  I've been at Microsoft for about two and a half years, and I work on the text editing and data binding features in Expression.  Since Expression is built on Windows Presentation Foundation(WPF), you'll hear me talk about that quite a bit as well.

-Alan

 
Page view tracker