看不到变量
unable to see variable
愚蠢的问题,但仍然。我有一些变量,让它成为 MyVariable
,它在代码隐藏的方法之一中获取它的值,例如在 MouseClick
中,但是 MyVariable
的值用于另一个 class 中的方法(我使用不同的模式)。当然,在这个class中MyVariable
是看不见的,但是有什么更好的呢?
public partial class MainWindow : Window
{
Hero Hero1 = new Hero();
Notify newNotify = new Notify();
public MainWindow()
{
InitializeComponent();
Collections coll = new Collections();
}
private void weapons_DragLeave(object sender, DragEventArgs e)
{
Hero1.Attack = ((Weapon) listweapons.SelectedItem)._attack;
newNotify.ThrowHero().Attack = Hero1.Attack;
newNotify.Dropped += Show_Message;
newNotify.DroppedEquipment();
TextBox2.Text = newNotify.ThrowHero().Description;//this gets its value from attack
}
public void Show_Message()
{
Console.WriteLine(newNotify.ThrowHero().Description =
"Защита:" + newNotify.ThrowHero().Protection + "атака:" + newNotify.ThrowHero().Attack);
}
}
然后我在另一个 class
中有另一个方法
public class SavingInWord : IWordSaving
{
public void ExportToWord()
{
var wordApp = new Word.Application();
wordApp.Visible = false;
Word.Document doc = wordApp.Documents.Add();
doc.Select();
wordApp.Selection.TypeText("Description:" + newNotify.ThrowHero().Description); //newNotify.ThrowHero().Description) can't be seen here, but i need to have the value here which i got from weapons_DragLeave method
doc.SaveAs(@"D:...doc");
wordApp.Visible = true;
}
}
另一个class:
public class Notify
{
Hero hero1 = new Hero();
public Hero ThrowHero()
{
return hero1;
}
public delegate void MyEventhandler();
public event MyEventhandler Dropped;
public void DroppedEquipment()
{
if (Dropped != null)
Dropped();
}
}
在你的最根部namespace
public static class Globals
{
Notify newNotify = new Notify();
}
然后您就可以随时随地访问它。
愚蠢的问题,但仍然。我有一些变量,让它成为 MyVariable
,它在代码隐藏的方法之一中获取它的值,例如在 MouseClick
中,但是 MyVariable
的值用于另一个 class 中的方法(我使用不同的模式)。当然,在这个class中MyVariable
是看不见的,但是有什么更好的呢?
public partial class MainWindow : Window
{
Hero Hero1 = new Hero();
Notify newNotify = new Notify();
public MainWindow()
{
InitializeComponent();
Collections coll = new Collections();
}
private void weapons_DragLeave(object sender, DragEventArgs e)
{
Hero1.Attack = ((Weapon) listweapons.SelectedItem)._attack;
newNotify.ThrowHero().Attack = Hero1.Attack;
newNotify.Dropped += Show_Message;
newNotify.DroppedEquipment();
TextBox2.Text = newNotify.ThrowHero().Description;//this gets its value from attack
}
public void Show_Message()
{
Console.WriteLine(newNotify.ThrowHero().Description =
"Защита:" + newNotify.ThrowHero().Protection + "атака:" + newNotify.ThrowHero().Attack);
}
}
然后我在另一个 class
中有另一个方法public class SavingInWord : IWordSaving
{
public void ExportToWord()
{
var wordApp = new Word.Application();
wordApp.Visible = false;
Word.Document doc = wordApp.Documents.Add();
doc.Select();
wordApp.Selection.TypeText("Description:" + newNotify.ThrowHero().Description); //newNotify.ThrowHero().Description) can't be seen here, but i need to have the value here which i got from weapons_DragLeave method
doc.SaveAs(@"D:...doc");
wordApp.Visible = true;
}
}
另一个class:
public class Notify
{
Hero hero1 = new Hero();
public Hero ThrowHero()
{
return hero1;
}
public delegate void MyEventhandler();
public event MyEventhandler Dropped;
public void DroppedEquipment()
{
if (Dropped != null)
Dropped();
}
}
在你的最根部namespace
public static class Globals
{
Notify newNotify = new Notify();
}
然后您就可以随时随地访问它。