C# Windows phone 8.1组合框样式图像

C# Windows phone 8.1组合框样式图像,c#,templates,combobox,windows-phone-8.1,styles,C#,Templates,Combobox,Windows Phone 8.1,Styles,我想将图像直接包含到组合框模板中 我找到了代码的这一部分,我相信我会把它放在这里: <Button x:Name="FlyoutButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" FontWeight="Normal" FlowDirection="{T

我想将图像直接包含到组合框模板中

我找到了代码的这一部分,我相信我会把它放在这里:

<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>

我不能在contentPresenter中放置图像,因为它说我只能设置“内容”一次

如果我做了如下的事情:

<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 Placeholder TextLock。”。在我选择一个项目后,图像也消失了


我希望您能提供一些指导。

我相信您希望将组合框中的项目设置为具有文本块的图像。在这种情况下,您需要如下设置组合框的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>

在页面资源中,您可以定义组合框项目的项目模板,如下所示

<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>

完成后,当您单击组合框运行它时,您可以看到带有图像的列表


希望这有帮助

这不完全是我想要的,但对我有点帮助。我终于得到了我想要的。谢谢你。我这么做了,但是:“谢谢你的反馈!一旦你赢得了总共15个声誉,你的投票将改变公开显示的帖子分数。”-Stackoverflow