0
我們正在試圖製作一個自定義控件,其中包含綁定到列表中的每個項目的文本框的一個包裝部分。創建自定義Silverlight控件
像這樣:
<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進入自定義控件?
謝謝!
那麼,這是一個簡單的例子,因爲演示的原因。我想重寫OnItemsSourceChanged,並在我的項目中可以使用的一個類中包含各種點擊事件。 –
我以爲是這樣。按照列出的步驟,如果您需要特殊項目,請不要忘記重寫'IsItemItsOwnContainerOverride'和'GetContainerForItemOverride'方法 - 每次都會收到我 – XAMeLi