我有一個組合框應該顯示兩個值,一個字符串和一個圖片。我列出了一些添加到ComboBox中的對象。這些對象具有字符串和位圖字段。我可以在我的ComboBox中顯示字符串,但是我找不到顯示位圖的方式。在組合框中顯示一個位圖對象
有什麼辦法可以讓<Image/>
顯示我的位圖嗎?
這是我的ComboBox XAML代碼,我知道這是行不通的,但我想不出另一種方式來做到這一點。我的表單窗口的
<ComboBox x:Name="typeBox" Grid.Column="1" HorizontalAlignment="Left" Margin="10,318,0,0" VerticalAlignment="Top" Width="300" Height="29">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding name}" Grid.Column="0" Grid.Row="0"/>
<Image Width="20" Height="20" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="1" Source="{Binding img}"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
C#代碼是相關的:我的資源
public NewRes()
{
pc = new PicChanger();
InitializeComponent();
typeBox.DataContext = GlowingEarth.types;
tagBox.DataContext = GlowingEarth.tags;
if (GlowingEarth.types.Count > 0)
{
foreach (Model.Type t in GlowingEarth.types)
{
typeBox.Items.Add(t);
}
}
if (GlowingEarth.tags.Count > 0)
{
foreach (Model.Etiquette t in GlowingEarth.tags)
{
tagBox.Items.Add(t);
}
}
}
C#代碼(類型和禮儀),這些相關的類:
public class Type
{
private string mark;
public string name { get; set; }
private string desc;
private Bitmap img;
public Type(string m, string n, string d, Bitmap mg)
{
mark = m;
name = n;
desc = d;
img = mg;
}
}
public class Etiquette
{
private string mark;
public string colCod { get; set; }
private string desc;
public Etiquette(string m, string c, string d)
{
mark = m;
colCod = c;
desc = d;
}
}
將檢查了這一點。謝謝!投了票:) – Riki