我正在使用現有的代碼。這件事有一個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