Je veux remplir une zone de liste déroulante avec des données clé/valeur dans le code derrière, j'ai ceci:Comment lier un ComboBox dictionnaire générique via ObjectDataProvider
XAML:
<Window x:Class="TestCombo234.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestCombo234"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ObjectDataProvider x:Key="Choices" ObjectType="{x:Type local:CollectionData}" MethodName="GetChoices"/>
</Window.Resources>
<StackPanel HorizontalAlignment="Left">
<ComboBox ItemsSource="{Binding Source={StaticResource Choices}}"/>
</StackPanel>
</Window>
code Derrière :
using System.Windows;
using System.Collections.Generic;
namespace TestCombo234
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
public static class CollectionData
{
public static Dictionary<int, string> GetChoices()
{
Dictionary<int, string> choices = new Dictionary<int, string>();
choices.Add(1, "monthly");
choices.Add(2, "quarterly");
choices.Add(3, "biannually");
choices.Add(4, "yearly");
return choices;
}
}
}
Mais cela me donne ceci:
alt text http://img193.imageshack.us/img193/9218/choices.png
Que dois-je changer pour que la clé est l'int et la valeur est la chaîne?
Google révèle ceci: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6f9ff9a9-9133-40cc-bfdb-a47d340658bf – Heinzi
On dirait que le l'image dans votre question ci-dessus est cassée (et maintenant [montrant une annonce à la place] (http://meta.stackexchange.com/questions/263771/ban-imageshack-images-parce que-les-ont-utilisé-sur-leurs-pour -La publicité)). Pourriez-vous s'il vous plaît ré-uploader l'image à stack.imgur, ou éditer votre question pour l'enlever? –