【发布时间】:2020-02-07 16:35:05
【问题描述】:
我在 WPF 应用程序中的 MainWindow.xaml.cs 中有这段代码
public partial class MainWindow : Window
{
animaciones.Preferences Preferences;
animaciones.GameOver GameOver;
ObservableCollection<Figura> listafiguras = new ObservableCollection<Figura>();
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
DispatcherTimer timer;
Raton raton;
public MainWindow()
{
InitializeComponent();
Preferences = new animaciones.Preferences();
GameOver = new animaciones.GameOver();
raton = new Raton();
player.SoundLocation = "lostwoods.wav";
Canvas.SetLeft(raton.fig, raton.x);
Canvas.SetBottom(raton.fig, raton.y);
lienzo.Children.Add(raton.fig);
this.KeyDown += new KeyEventHandler(KeyDownEventos);
timer = new DispatcherTimer();
timer.Tick += OnTick;
timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
}
我想像这样在另一个 xaml.cs 中使用“listafiguras”ObservableCollection:
public partial class Preferences : Window
{
public Preferences()
{
InitializeComponent();
tabla.ItemsSource = MainWindow.listafiguras;
}
但它说 MainWindow 由于其保护级别而无法访问。如何更改它以访问我的变量?谢谢
【问题讨论】:
标签: c# wpf xaml mainwindow