動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
@ WPF 4.5入門 by 大田一希さん
No.1400 / 9985
「コンテンツ構文」の例がButtonに対して紹介されている。
System.Windows.Markup.contentPropertyAttribute属性でコンテンツプロパティが指定されている場合に限りプロパティ名を省略して書くことが出来ます。
作成済みのComboBoxで試してみた。
XAML
<Window x:Class="_170423_t1630_combobox.MainWindow"
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:local="clr-namespace:_170423_t1630_combobox"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox HorizontalAlignment="Left"
Margin="37,29,0,0"
VerticalAlignment="Top" Width="120">
<ComboBox.Items>
<Label>
<Label.Content>
AAA
</Label.Content>
</Label>
<Label>
BBB
</Label>
<Label Content="CCC"/>
</ComboBox.Items>
</ComboBox>
</Grid>
</Window>
AAAが省略してない場合、BBBは省略した場合。
大田さんの本の中では[ContentProperty("Children")]
のようにしてcontentPropertyAttributeを変更する例もある。
関連リンク
以下もシンプルでわかり易いです。
http://d.hatena.ne.jp/Yamaki/20061222/1166756248