ASP.NET controls like ListView allows providing a custom template by setting the ListView.EmptyDataTemplate property, this template will be rendered in case of empty data source
you can use DataTemplate selector to do that.
http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector.aspx
UPDATE 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace EmptyRowsTemplate
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += (o, e) =>
{
this.l.ItemsSource = new List(3)
{
"A",
null,
"B"
};
};
}
}
public class TemplateManager : DependencyObject
{
public static readonly DependencyProperty BlankDataTemplateProperty =
DependencyProperty.RegisterAttached("BlankDataTemplate",
typeof(DataTemplate),
typeof(TemplateManager),
new PropertyMetadata(new PropertyChangedCallback((o, e) =>
{
((ItemsControl)o).ItemTemplateSelector = new BlankDataTemplateSelector();
})));
public static void SetBlankDataTemplate(DependencyObject o, DataTemplate e)
{
o.SetValue(TemplateManager.BlankDataTemplateProperty, e);
}
public static DataTemplate GetBlankDataTemplate(DependencyObject o)
{
return (DataTemplate)o.GetValue(TemplateManager.BlankDataTemplateProperty);
}
private class BlankDataTemplateSelector : DataTemplateSelector
{
public BlankDataTemplateSelector()
: base()
{
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
ItemsControl itemControl =
(ItemsControl)ItemsControl.ItemsControlFromItemContainer(ItemsControl.ContainerFromElement(null, container));
if (item == null)
{
return TemplateManager.GetBlankDataTemplate(itemControl);
}
else
{
return base.SelectTemplate(item, container);
}
}
}
}
}
Markup