Thursday, April 30, 2009

ScatterView in Microsoft Surface SDK

Microsoft SDK provides a control named ScatterView which acts like a container and we can move,resize or rotate the object which is placed inside the ScatterView Container.There is no need to create events or code for doing this.ScatterView will automatically handle all the Events.Definitely users will find this as a very cool feature.I created my first Surface application with ScatterView.Its pretty simple doing this and of course cool.

  • Create a Surface Project from Visual Studio Template.
  • Add ScatterView Control.

ScatterView contains collection of ScatterViewItem.Add Objects to ScatterView either inside a ScatterViewItem or we can directly add objects to the ScatterView.

The ScatterView looks either like,

<s:ScatterView>
<s:ScatterViewItem Width="200" Height="200" Center="500,300"
Orientation="315" >
<Image Source="Images/Forest.jpg" Stretch="Fill"></Image>
</s:ScatterViewItem>
</s:ScatterView>

OR like,

<s:ScatterView>
<Image Source="Images/Forest.jpg" Stretch="Fill"></Image>
</s:ScatterView>

I am adding an Image to the ScatterView so that we can manipulate like resize,rotate or move the image.




Monday, April 27, 2009

IValueConverter in WPF

Converters are mainly using in WPF when there is a need to convert a value to another value just like converting a Boolean to Visibility.

public class CustomConverter : IValueConverter
{
#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
if (value ==null)
return false;
return true;

}

public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}

#endregion
}

Here CustomConverter is implementing IValueConverter.We can use this converter in the XAML.First add this Converter in the resources,
<local:CustomConverter x:Key="CustomConverter" />
where local is the reference to the assembly where CustomConverter is defined.
Use this Converter in Controls DataBinding like,
IsEnabled="{Binding ElementName=ListBoxName, Path=SelectedItem,
Converter={StaticResource CustomConverter}}"