【发布时间】:2011-08-11 05:07:43
【问题描述】:
我们正在尝试创建一个自定义控件,该控件包含绑定到它的列表中的每个项目的文本框的包裹部分。
像这样:
<ItemsControl x:Name="asdf">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
但是,当我们把它变成一个自定义控件时,它不会将 ItemsPanel 设置为 WrapPanel,也不会做 ItemTemplate:
<ItemsControl x:Class="SilverlightApplication1.PillTagBox"
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"
xmlns:controls= "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
它只是显示了项目的绑定列表,就像根本没有样式一样:
<ItemsControl x:Name="asdf" />
我们如何将第一块 XAML 变成自定义控件?
谢谢!
【问题讨论】:
标签: silverlight xaml