[英]How to set icon and background color to Combox item in Windows Phone 8.1
我想改善Windows Phone 8.1應用程序中Combobox項的布局。 默認情況下,組合框項目將類似於以下內容:
我想為每個項目設置圖標和背景,具體取決於插入對象的屬性(如果可以,則為綠色;如果不正常,則為橙色;如果出現錯誤,則為紅色)。 我能怎么做 ? 所以我想要這樣,在藍色的背景下,也要為特定情況設置(前面的示例應該清楚)。
您可以通過將ComboBox項使用DataTemplate來實現。 您可能必須使用轉換器作為背景色。
<ComboBox ItemsSource="{Binding ListOfProperties}" SelectedValuePath="Id">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid Background="{Binding ColorName, Converter={StaticResource StringToBrushConverter}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Source="{Binding ImageUrl}"/> // "ms-appx:///Assets/image.png" for example
<TextBlock Grid.Column="1" Text="{Binding Text}"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.