![](/img/trans.png)
[英]ComboBox selected item in windows 8.1 or windows phone 8.1
[英]Windows phone 8.1 ComboBox style Image
我想将图像直接包含在ComboBox模板中。
我找到了代码的这一部分,我相信这里是我要放置的部分:
<Button x:Name="FlyoutButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" FontWeight="Normal" FlowDirection="{TemplateBinding FlowDirection}" FontSize="{ThemeResource ContentControlFontSize}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" MinHeight="{ThemeResource ComboBoxItemMinHeightThemeSize}" Padding="6.5,0,0,0" Grid.Row="1">
<ContentPresenter x:Name="ContentPresenter" Margin="0,0.8,0,0" MinHeight="32.5">
<TextBlock x:Name="PlaceholderTextBlock" Margin="0" Style="{StaticResource ComboBoxPlaceholderTextBlockStyle}" Text="{TemplateBinding PlaceholderText}"/>
</ContentPresenter>
</Button>
我不能将Image放入contentPresenter内,因为它说我只能设置一次'Content'。
如果我做类似的事情:
<ContentPresenter x:Name="ContentPresenter" Margin="0,0.8,0,0" MinHeight="32.5">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="PlaceholderTextBlock" Margin="0" Style="{StaticResource ComboBoxPlaceholderTextBlockStyle}" Text="{TemplateBinding PlaceholderText}"/>
<Image Source="ms-appx:///Assets/Arrow.png" />
</StackPanel>
</ContentPresenter>
它实际上可以正常工作,但在XAML视图页面中出现错误:“未检测到已安装的组件。无法解析TargetName PlaceholderTextlock。”。 而且,选择项目后图像也会消失。
我希望得到一些指导。
我相信您希望在组合框中设置项目以使图像带有文本块。 在这种情况下,您需要像这样设置组合框的ItemTemplate
<ComboBox Name="hik" ItemTemplate="{StaticResource cmbx}">
在页面资源中,您可以为组合框项目定义项目模板,如下所示
<DataTemplate x:Key="cmbx">
<StackPanel Orientation="Horizontal" Background="Aqua">
<TextBlock HorizontalAlignment="Left" Margin="0,0,0,0" Foreground="Black" TextWrapping="Wrap" Text="Some Text" VerticalAlignment="Top"/>
<Image Source="/Assets/1.png" Stretch="Uniform" Height="100" Width="100" />
</StackPanel>
</DataTemplate>
一旦单击组合框运行它,就可以看到带有图像的列表
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.