我正在使用现有的代码。这件事有一个ComboBox与几个ComboBoxItems。每个项目都有一个StackPanel,里面有一个Image控件和一个TextBlock。使用DataTemplate在ComboBox中绑定图像
现在,Image控件的source属性设置为存储在XAML文件中的不同矢量图像,而TextBlock的Text属性设置为本地化字符串。
我想通过使用DataTemplate单独使用ComboBoxItems来实现此目的。我可以为TextBlock创建一个字符串列表,但我无法弄清楚如何将图像绑定到各自的图像控件。
我接受任何其他更好的解决方案。另外,如果您认为正确的做法是现有的,请告诉我。
这可能是一个重复的问题,但我找不到满足我的问题的问题。 如果是,则指向其他问题的链接就足够了。
编辑:代码添加
<ComboBox x:Name="imageInfoLevelsComboBox" SelectedIndex="1"
Style="{DynamicResource ComboBoxToolBarStyle}"
Margin="6,6,6,0" Width="50"
ToolTip="{x:Static Viewing:ViewingTexts.ImageInformationLevels}"
SelectionChanged="OnImageInfoLevelsComboBoxSelectionChanged" >
<ComboBoxItem x:Name="showAllComboBoxItem"
Style="{DynamicResource ComboBoxItemToolBarStyle}">
<StackPanel Orientation="Horizontal">
<Image x:Name="ImageInfoAllImage"
Source="{StaticResource ImageInfoFullIcon}"
Margin="0,0,4,0"
Width="24" Height="24"/>
<TextBlock
Text="{x:Static Viewing:ViewingTexts.ImageInformationFull}"
Margin="10,0,0,0"
VerticalAlignment="Center"/>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem x:Name="showImportantComboBoxItem"
Style="{DynamicResource ComboBoxItemToolBarStyle}">
<StackPanel Orientation="Horizontal">
<Image x:Name="ImageInfoImportantImage"
Source="{StaticResource ImageInfoLimitedIcon}"
Margin="0,0,4,0"
Width="24" Height="24"/>
<TextBlock
Text="{x:Static Viewing:ViewingTexts.ImageInformationIntermediate}"
Margin="10,0,0,0"
VerticalAlignment="Center"/>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem x:Name="showNotificationsComboBoxItem"
Style="{DynamicResource ComboBoxItemToolBarStyle}">
<StackPanel Orientation="Horizontal">
<Image x:Name="ImageInfoNotificationsImage"
Source="{StaticResource ImageInfoNoneIcon}"
Margin="0,0,4,0" Width="24" Height="24"/>
<TextBlock Text="{x:Static Viewing:ViewingTexts.ImageInformationNone}"
Margin="10,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
</ComboBoxItem>
</ComboBox>
我想我可以做的就是创建一个类有2个对象,字符串类型之一,另一个为图像。然后创建一个列表并将其与组合框绑定,但问题是我无法确定如何将矢量图像用作对象。
谢谢。
请查看现有的XAML – mathieu 2013-02-28 10:56:11
@mathieu结合 - 发布供大家参考代码。 – 2013-02-28 11:48:17