* You are viewing the archive for the ‘Silverlight’ Category

Memory Leak in PanelDragDropTarget

While implementing drag-and-drop grouping for the Silverlight DataGrid I noticed that the PanelDragDropTarget contains a memory leak:

Whenever you add a user control containing a PanelDragDropTarget to a page and then remove the user control from this page, the user control is not properly released.

When you replace the PanelDragDropTarget with another control, e.g. a ListBox, the user control is released.

The root cause of this problem is probably the fact that the base class DropDragTarget attaches some events to the Canvas of the Application.Current which are not removed.

I have created a sample project that demonstrates the problem using the MemoryLeakDetector which … Continue Reading

Datagrid: support for grouping on columns use IValueConverters to display their value and conditonal rowstyling

DataGrid update

Introduction

Some further enhancements have been made to the DataGrid wrapper that has been the subject of this previous post:

  • Support for grouping on columns that use IValueConverter to display their value
  • Conditional row styling

This post is a code drop for these enhancements.

Conditional row styling

The following code gives a sample on how to use conditional row styling:

public MainPage()
{
InitializeComponent();

theDataGrid.ItemsSource = PersonFactory.GetAllPersons();

theDataGrid.RowStyles.Add(new MyDataGridRowConditionalStyle(
(o) => { return ((Person)o).Name.Contains(“A”); },
Continue Reading

Update postings on Datagrid

Recently I wrote two posts on the Silverlight Datagrid:

Andy noticed that in a comment that the synchronizing of the group row headers with the column headers did not work correctly when the group headers were scrolled out of view and then back into view again.

After investigating the reason of this behavior I have decided to take another approach and to re-implement this functionality. Some additional testing of this new implementation reveals that the issue reported by Andy has been solved. The only quirk … Continue Reading

Drag and Drop grouping in Datagrid

Update

The code for the functionality in this post has been updated in Update postings on Datagrid

Introduction

The DataGrid of the Silverlight Toolkit supports grouping but does not have the ability to drag column headers to the area above the grid to group the data, unlike some other 3rd party datagrids.

This blog presents a solution to implement this functionality. The solution is based upon the solution which can be found on the blog Lee’s corner. … Continue Reading

Synchronizing group row headers with column headers in Silverlight DataGrid

Update

The code for the functionality in this post has been updated in Update postings on Datagrid

Grouping in the DataGrid in Silverlight is quite easy. What is not so obvious is how to change the caption of the column name on the group row. It turns out that you could use the LoadingRowGroup of the DataGrid:

theGrid.LoadingRowGroup += (s, e) =>
{
e.RowGroupHeader.PropertyName = “A custom caption”;
}

The original value of the e.RowGroupHeader.PropertyName is the PropertyName of the PropertyGroupDescription. Using this value the column header can be determined:

private string GetColumnCaption(DataGrid grid, string columnName)
{
Continue Reading

INotifyPropertyChanged: automatic dependent property and nested object support

Summary

The hardest problem with INotifyPropertyChanged is often overlooked: dependency management. When one property is changed, all of its dependent properties need to fire as well.

This blog presents another solution based on dynamic dependency determination.

Table of contents

INotifyPropertyChanged implementations: An Overview

Summary

One of the cornerstones of MVVM is the INotifyPropertyChanged interface. This post describes several implementations that have been used/proposed over time.

Table of contents

Introduction

One of the cornerstones of MVVM is the INotifyPropertyChanged interface. This post describes several implementations that have been used/proposed over time.

The basic ingredient of each INotifyPropertyChanged implementation is the … Continue Reading

Silverlight DataContext Changed Event and Trigger

Silverlight does not provide a DataContextChanged event. Several solutions have been created for this problem. The solution presented here is based on two attached properties instead of one. The advantage of this solution is that multiple event handlers can be attached and this solution does not force the developer to implement a specific interface like the solution presented here.

The heart of the solution consists of the static class DataContextChangedHelper. This class uses the attached property named InheritedDataContext which is bound to the DataContext of the FrameworkElement. Whenever the DataContext is changed, the value of InheritedDataContext (due to the binding) … Continue Reading

Localization of XAML files in Silverlight

This post describes a walk-through of the steps to perform in order to localize XAML files in Silverlight. This post is based on Silverlight 4, but all the steps do also apply to Silverlight 3. The full source code of the resulting project can be downloaded here. The language C# is used throughout this post, but the steps are easy translatable to VB.NET.

First create a Silverlight application solution using Visual Studio 2010 named LocalizationWalkThrough and close the solution after it has been created. Now open the project file LocalizationWalkThrough\LocalizationWalkThrough.csproj with your favorite text editor, and locate the tag SupportedCultures. … Continue Reading

Passing parameters to a Silverlight XAP application

In this post two ways to pass parameters to an in-browser Silverlight application without modifying the XAP are described:

  • Using the querystring of the containing HTML/ASP.NET page
  • Using the InitParams attribute of the object tag that hosts the XAP file

The first method is straight forward: just add a querystring to the URL. You can retrieve the querystring using the HtmlPage.Document like this (based on code from MSDN):

private void Application_Startup(object sender, StartupEventArgs e)
{
Page p = new Page();
this.RootVisual = p;

// This assumes that Page.LayoutRoot exists and is a StackPanel.
Continue Reading

Page 1 of 212