I have a WPF window containing a ListBox. The ItemsSource element is bound to a property of the view model.
<Window x:Class="SimpleWpfApp.View.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
DataContext="{Binding MainWindowViewModel, Source={StaticResource Locator}}">
<DockPanel>
<ListBox ItemsSource="{Binding SomeThings}" />
</DockPanel>
</Window>
A view model property is an observable collection of user interfaces; ISomeInterface. The interface is very simple and implemented by SomeClass, which further overrides ToString.
public class MainWindowViewModel
{
public ObservableCollection<ISomeInterface> SomeThings
{
get
{
var list = new List<ISomeInterface>
{
new SomeClass {Value = "initialised"},
new SomeClass {Value = "in"},
new SomeClass {Value = "code"}
};
return new ObservableCollection<ISomeInterface>(list);
}
}
}
public interface ISomeInterface
{
string Value { get; }
}
public class SomeClass : ISomeInterface
{
public string Value { get; set; }
public override string ToString() => Value;
}
When I view a window in Visual Studio 2015 or Blend, everything is as expected. Called ToString and populated ListBox.
Hide screenshot
I created the XAML design data that I want to use in design mode. I added design data to the SampleData directory. I add the datacontext constructor to the XAML window right below the first DataContext.
d:DataContext="{d:DesignData Source=/SampleData/Data.xaml}"
. Visual Studio Blend " " , . /SampleData/Data.xaml, SampleData/Data.xaml,../SampleData/Data.xaml,./../SampleData/Data.xaml
Visual Studio Blend Data.xaml, SampleData . /Data.xaml Data.xaml. Data.xaml /, Visual Studio Blend , .. .
: ? , ?
Data.xaml , ToString, . , , , -, .
: ToString , , ?
, , .
<ListBox ItemsSource="{Binding SomeThings}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
github
https://github.com/DangerousDarlow/WpfDesignData
jstreet . data.xaml , . , , .
ToString. List<object>, List<ISomeInterface>, object.ToString; . , , , ToString , , . , .
Visual Studio 2015.