Delay's Blog is the blog of David Anson, a Microsoft developer who works with the Silverlight, WPF, Windows Phone, and web platforms.
http://dlaa.me/
@DavidAns
One scenario I've seen cause a bit of trouble on the Silverlight Controls Forum is that of putting a Button in a ListBox. There are two aspects of this that seem to cause difficulty and I thought it would be helpful to demonstrate the complete scenario in a runnable, self-contained sample. (Please Download the ZIP file attached to the bottom of this post for all the code/XAML in a ready-to-go Visual Studio 2008 + Silverlight Tools solution.) While I was developing the sample, I threw in a couple of other handy techniques that may not be widely known. The sample application shows a typical shopping cart experience where products are listed and their quantities can be interactively changed:
Details on the button scenario:
Release
Press
<Button ... ClickMode="Press" ... />
<Button ... Click="Add_Click" ... />
Other points of interest:
Product
For lots more about configuring and using ListBox, please see my ListBox/ScrollViewer FAQ.
Quantity
public int Quantity { get { return _quantity; } set { _quantity = value; // Fire PropertyChanged event to notify listeners of changed value var handler = PropertyChanged; if (null != handler) { handler.Invoke(this, new PropertyChangedEventArgs("Quantity")); } } } private int _quantity; public event PropertyChangedEventHandler PropertyChanged;
bool
int
// Simple IValueConverter returns true iff the value is positive // Used to toggle Remove button's IsEnabled when Quantity changes between 0 and 1 public class IntIsPositive : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (0 < ((int)value)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
At the risk of straying too far from the original scenario, I think the additional techniques I've shown here support it nicely and improve the user experience notably. I hope this sample helps people with their own projects - and maybe introduces a useful trick or two!
Enjoy!
After a few customer requests to update my SimpleSilverlightXpsViewer proof-of-concept XPS reader for Silverlight 2 Beta 1, I finally found time to do so. :) I've just updated the original SimpleSilverlightXpsViewer demonstration page and also updated the original source code download - so you can try it out in your own browser and/or download the code to see how it works!
Click on the image above to play around with the application in your browser. More details about what it is doing and how it works are available in the original SimpleSilverlightXpsViewer post.
Notes:
#define SETSOURCE
#if
#endif
Kind readers gave some great feedback on my previous post of the ConvertClipboardRtfToHtmlText tool and source code. Accordingly, I have made three small tweaks to the tool:
The sample code and tool in the previous post have been updated with these changes, so please go there to get the latest version.