I have the following xaml -
<Window x:Class="DataTemplateTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="400" Width="600" Loaded="Window_Loaded">
<Grid>
<ListBox Height="380" Margin="10,12,0,0" Width="355"/>
</Grid>
</Window>
and the following code-behind -
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_nameList = new List<string>
{
"X",
"Y",
"Z"
};
}
private List<string> _nameList;
public List<string> NameList
{
get { return _nameList; }
}
}
I want to set the NameList
as the ItemsSource
of the ListBox from the xaml, not from the code-behind. How do I do that?
EDIT : I know the MVVM-way of doing this. But that's not what I'm asking.
EDIT : It's not that I don't like MVVM or so. While doing some quick test I just realized that I don't know how to do this. So, wondering if it's possible, and trying to learn. Is it anyhow possible using StaticResource
?