我目前在樣式ComboBox
看起來像一個在Visual Studio(與顏色主題一起)。我完成了大部分樣式,但在ContentPresenter
處停止顯示當前選擇的對象。如何在ComboBox中設置ContentPresenter的風格?
這件作品的XAML如下所示:
<ContentPresenter Margin="2" IsHitTestVisible="False" VerticalAlignment="Center" HorizontalAlignment="Stretch"
Name="ContentSite"
ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
Content="{TemplateBinding ComboBox.SelectionBoxItem}" />
的問題是,默認SelectionBoxItemTemplate
似乎忽略組合框的前景值:
<ComboBox Margin="4" SelectedIndex="0" Foreground="Red">
<ComboBoxItem>First</ComboBoxItem>
<ComboBoxItem>Second</ComboBoxItem>
<ComboBoxItem>Third</ComboBoxItem>
</ComboBox>
第一個是不可編輯的,SelectionBoxItemTemplate
啓動並強制將文本的顏色設置爲黑色(即使手動將設置爲紅色,並將樣式設置爲另一種非黑色顏色)。
如何將當前前景色傳遞給ContentPresenter
?如果我不能,我在哪裏可以找到工作替代SelectionBoxItemTemplate
? (對於ComboBox
中的所有物品類型,其工作正常)