![](/img/trans.png)
[英]WPF Image control doesn't display ImageSource that was added/assigned programatically
[英]Image doesn't display when control is assigned from static object
我正在使用WinForms在C#中制作紙牌游戲。 我遇到的問題使我無法前進,因為我想添加用戶制作的內容。 目的是通過聲明的任何資源/文件將圖像動態設置為卡片。 讓我們看一下我的代碼。
這是ExpansionInit.cs
public static Card CopperCard = new Card
{
Name = "Copper",
ID = 0,
BuyValue = 0,
Type = CardType.Treasure,
TreasureValue = 1,
StackCount = GetCardStack(0),
};
這是GameGUI.cs
using System;
using System.Windows.Forms;
using Dominion.Expansions.Base;
using Dominion.Properties;
namespace Dominion
{
public partial class GameGui : Form
{
public GameGui()
{
Game.StartGame();
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//new HandGUI().Show();
cardCopper = ExpansionInit.CopperCard;
cardCopper.BackgroundImage = Resources._0_copper;
}
}
}
這是Card.cs
我不確定這部分內容是否很重要,但是如果您能在其中找到可能導致問題的內容,
using System.Windows.Forms;
using Newtonsoft.Json;
namespace Dominion.Cards
{
public delegate void CardActivationHandler(Card c, Player p);
[JsonObject(MemberSerialization.OptIn)]
public sealed partial class Card : UserControl
{
// ReSharper disable once InconsistentNaming
[JsonProperty]
public int StackCount;
[JsonProperty]
public int ID;
[JsonProperty]
public int TreasureValue;
[JsonProperty]
public int VictoryValue;
[JsonProperty]
public int BuyValue;
[JsonProperty]
public CardType Type;
[JsonProperty]
public CardActivationHandler Handler;
[JsonProperty]
public new string Text { get; set; }
[JsonProperty]
public new string Name { get; set; }
public Card()
{
InitializeComponent();
}
}
public enum CardType
{
Victory, Treasure, Action, Other
}
}
需要讀取對象form1.Controls.Add(cardCopper)
和位置重置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.