【发布时间】:2012-01-10 07:39:15
【问题描述】:
我试图弄清楚为什么这个代码
<UserControl x:Class="TestSilverlight.MainPage"
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" d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Button x:Key="button" Content="{Binding}" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Yellow">
<ListBox Name="listBox">
<ListBox.ItemTemplate>
<DataTemplate>
<ContentControl Content="{StaticResource button}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
using System.Collections.Generic;
namespace TestSilverlight
{
public partial class MainPage
{
public MainPage()
{
InitializeComponent();
listBox.ItemsSource = new List<string> {"a", "b", "c"}; //without this line it works
}
}
}
不起作用。它抛出解析器异常(无法在 ContentControl 中设置属性 Content)。没有绑定它可以完美地工作。还好吗?
【问题讨论】: