我一遍又一遍地重復相同的代碼:
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel Orientation="Vertical">
<Label Content="Content 1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ComboBox Style="{StaticResource CustomComboBox}"/>
</StackPanel>
</StackPanel>
它始終是輸入控制元件(文本框、組合框、...)和標簽的某種組合。
我已經搜索過
uj5u.com熱心網友回復:
AContentControl應該使用 a ContentTemplate:
<Window.Resources>
<DataTemplate x:Key="ComboWithHeader">
<StackPanel Orientation="Vertical">
<Label Width="120" Height="25" Content="{TemplateBinding Content}"/>
<ComboBox Width="120" Height="25"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl Content="My Header" ContentTemplate="{StaticResource ComboWithHeader}"/>
</Grid>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/483197.html
