Silverlight: image to byte[]

(the bits per pixel method you are missing just details how the color information is stored per pixel) As anthony suggested, a WriteableBitmap would be the easiest way – check out for a method to get an argb byte array out : public static byte[] ToByteArray(this WriteableBitmap bmp) { // Init buffer int w … Read more

Is there any difference in x:name and name for controls in xaml file?

In Brief Yes there is a difference. The bottom line is that x:Name can be used on object elements that do not have Name properties of their own. A longer explanation You can only use Name on an element that represents an object that actually does have a Name property. For example anything that derives … Read more

Iterating through an enumeration in Silverlight?

Or maybe strongly typed using linq, like this: public static T[] GetEnumValues<T>() { var type = typeof(T); if (!type.IsEnum) throw new ArgumentException(“Type ‘” + type.Name + “‘ is not an enum”); return ( from field in type.GetFields(BindingFlags.Public | BindingFlags.Static) where field.IsLiteral select (T)field.GetValue(null) ).ToArray(); } public static string[] GetEnumStrings<T>() { var type = typeof(T); if … Read more

Access ResourceDictionary items programmatically

Got it solved. I needed to: load my resource dictionary merge it with the application’s resources load my control template from the application resource As part of loading the resource dictionary, i also had to register the pack URI scheme. I then had to deal with some crazy COM based exceptions due to slight errors … Read more

MVVM light – how to access property in other view model

You could use the Messenger to do this: Send the user in the UserViewModel: Messenger.Send<User>(userInstance); would just send the user to anyone interested. And register a recipient in your CardViewModel: Messenger.Register<User>(this, delegate(User curUser){_curUser = curUser;}); or you can also send a request from your CardViewModel for shouting the user: Messenger.Send<String, UserViewModel>(“Gimme user”); And react on … Read more

Dynamically setting the Header text of a Silverlight DataGrid Column

You can’t Bind to Header because it’s not a FrameworkElement. You can make the text dynamic by modifying the Header Template like this: xmlns:data=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data” xmlns:dataprimitives=”clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data” <data:DataGridTemplateColumn> <data:DataGridTemplateColumn.HeaderStyle> <Style TargetType=”dataprimitives:DataGridColumnHeader”> <Setter Property=”Template”> <Setter.Value> <ControlTemplate> <TextBlock Text=”{Binding MeetingName, Source={StaticResource LocStrings}}” /> </ControlTemplate> </Setter.Value> </Setter> </Style> </data:DataGridTemplateColumn.HeaderStyle> </data:DataGridTemplateColumn>

Creating a Silverlight DataTemplate in code

Although you cannot programatically create it, you can load it from a XAML string in code like this: public static DataTemplate Create(Type type) { return (DataTemplate) XamlReader.Load( @”<DataTemplate xmlns=””″”> <” + type.Name + @”/> </DataTemplate>” ); } The snippet above creates a data template containing a single control, which may be a user control with … Read more