DCSIMG
WPF,Silverlight - Pavel's Blog
Sign in | Join | Help

Pavel's Blog

Pavel is a software guy that is interested in almost everything
software related... way too much for too little time

Browse by Tags

XAML Tip: Graphics with ItemsControl
23 February 13 12:04 AM | pavely | with no comments
Sometimes in a WPF or Windows Store or Windows Phone application we need to draw some things based on some collection of data items. Suppose we have the following simple data item: class CarData { public double Distance { get; set; } public string Image { get; set; } } Suppose we have a collection of CarData objects, and the requirement was to show a set of images along a line with a particular distance, like in the following screenshot: The distance from the left is determined by the Distance property...
Preview of Blend 5 available
25 December 12 03:41 AM | pavely | with no comments
When Visual Studio 2012 came out, one thing was sorely missing. An Expression Blend tool that can handle WPF 4.5 applications. Blend for Visual Studio that is currently available only supports Windows 8 Store Apps, but not WPF (or Silverlight). A few days ago, Microsoft released a preview of Blend 5 (with Sketchflow), that’s able to work with WPF and Silverlight, along with Windows 8 Store apps. The tool can be downloaded from here: http://www.microsoft.com/en-us/download/details.aspx?id=30702 Microsoft...
Windows 8 Metro: Detecting scroll changes in ListView
02 July 12 09:27 PM | pavely | with no comments
I had a requirement in a Metro app I’m working on to detect scrolling in a ListView ( GridView is practically the same), or more precisely, detect whether the selected item goes off the visible ListView area, and if so, switch some items in the ListView so that the selected item be visible again; this is not an entirely accurate description, but it’s close enough for our purposes. An easy one, right? Searching the ListView class (and its bases) yields no useful results on scrolling. In WPF, the ScrollViewer...
INotifyPropertyChanged implementation with C# 5.0
20 March 12 10:40 PM | pavely | 6 comment(s)
The INotifyPropertyChanged interface has become a very popular interface, typically used in MVVM scenarios (WPF/Silverlight). It looks simple, with a single member, which is an event, and its basic implementation by some data type may be something like this: class Book : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged( string propName) { var pc = PropertyChanged; if (pc != null ) pc( this , new PropertyChangedEventArgs (propName...
WPF/Silverlight Tip: Transparent Hit Testing
23 February 12 08:56 AM | pavely | with no comments
Hit testing is the process of finding out which elements (if any) contain a certain point (typically the location of the mouse pointer). Sometimes, however, there is a need to disregard some elements in a hit testing scenario. Consider this simple program that allows moving of circles: One can grab a circle and drag it around. Here’s the MouseLeftButtonDown event handler on the containing Canvas: void OnMouseDown( object sender, MouseButtonEventArgs e) { var shape = e.Source as Shape ; if (shape...
תגים:, , , ,
A UniformGrid for Silverlight/Windows Phone
07 February 12 10:00 PM | pavely | 1 comment(s)
The UniformGrid panel in WPF has some useful features, especially as an items panel in an ItemsControl . I blogged about the usefulness of the UniformGrid here . But what about Silverlight? It has no UniformGrid , but we can create one as a custom panel. This would be usable in Silverlight for the desktop and for Windows Phone, and would be a simple enough example to show in one post. The layout process In WPF/Silverlight, layout is a two step process. The first step is Measure: the panel asks each...
WPF Tip: Displaying Images in different Pixel formats
30 January 12 12:25 AM | pavely | 3 comment(s)
If we want to show an image in WPF, we typically use an Image element and connect its Source property to some image resource within our project: < Image Source ="Penguins.jpg" /> The Source property is not a string, it’s an ImageSource – an abstract type with several concrete implementations that provide a “real” image source. The above markup works thanks to the help of a type converter, that makes the source a BitmapImage – one of the simplest sources, that presents the image as...
WPF/Silverlight Data Binding Tip: FallbackValue
25 June 11 03:44 PM | pavely | with no comments
Consider the following piece of XAML (part of an Image Viewer application), that wants to set the Window title (in WPF) based on the currently loaded image file: Title ="{ Binding ImagePath , StringFormat =Image Viewer ({ 0} )}" This assumes that a DataContext exists, and exposes a property named ImagePath . This works well if such an object actually exists. But what happens when the application starts up and there is no image loaded yet, meaning the DataContext remains null? The Title...
תגים:, , , ,
Some Short Videos I Made
26 May 11 02:30 PM | pavely | with no comments
I’ve created a few short videos, covering some introductory material – still may be useful for some… The audio quality is not the best possible, but should be fairly understandable. All the videos are in Hebrew (sorry, non-Hebrew speakers! You can still watch me type code samples, it may have some value) The videos are: Introduction to C# 5.0 asynchronous programming Introduction to the Managed Extensibility Framework (MEF) Understanding XAML (Part 1) Understanding XAML (Part 2)   They are also...
Silverlight Quirk: Content Alignment not respected for ListBox
23 August 10 08:38 PM | pavely | 2 comment(s)
Silverlight and WPF have many similarities, and many differences as well. One of the subtle ones I’ve discovered is with respecting the HorizontalContentAlignment property in a ListBox. Here’s the same application, written in WPF and Silverlight with the following ListBox (bound to a collection of Book objects) and its item template:    < ListBox HorizontalContentAlignment = "Stretch" x : Name = "_list" >         < ListBox...
תגים:, , , , ,