我有这个用户控制 XAML:
<Window x:Class="MyProj.Dialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
mc:Ignorable="d">
<Grid>
<ItemsControl ItemsSource="{Binding Foos}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="ASd" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
以及后面的相应代码:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Effects;
using System.Windows.Threading;
namespace MyProj
{
public partial class Dialog : Window
{
public Dialog() : base()
{
InitializeComponent();
//DataContext = this;
}
public ObservableCollection<string> Foos = new ObservableCollection<string> { "foo", "bar" };
}
}
我遇到的问题是由于某种原因ItemsControl
没有显示任何内容。奇怪的是,我什至没有在输出中收到绑定警告。