私には2つの値、文字列と画像が表示されるはずのコンボボックスがあります。私は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