我試圖建立一個用戶控件至極能夠採取元素從XAML這樣的:如何在WPF用戶控件一樣創建組合框
<ComboBox >
<ComboBoxItem />
<ComboBoxItem />
<ComboBoxItem />
</ComboBox>
在ComboBox
,你可以添加ComboBox
之間的項目標籤,我想複製這個,但我不知道從哪裏開始。
完成了它應該是這樣的:
<cis:ReportControl Grid.Row="3">
<cis:ReportItem />
</cis:ReportControl>
在cis:ReportControl
,也有一些Button
S和ComboBox
,基本上我只是想與項目喂ComboBox
。
該報告項目只是一個ComboBoxItem
與一些額外的屬性。
編輯:
我根據@Snowbears答案實現了它,但現在的問題是,控制其自身作爲一個項目。 我認爲這是因爲我有一些內容,並通過將ContentProperty
定義爲我的ComboBox
,它被重定向到Box中。 我能做些什麼來避免這種情況?
編輯II:
它完全與這個工程現在:
private ItemCollection reportItems;
public ItemCollection ReportItems
{
get
{
if (reportItems == null)
{
reportItems = this.ComboBoxReports.Items;
}
return reportItems;
}
}
與[ContentProperty("ReportItems")]
屬性。 ComboBoxReports是控件中的ComboBox,我不得不繼承ItemsControl
以使其起作用。