我在MainWindow.xaml.cs中有这样的代码:
public partial class MainWindow : Window
{
public double _frameCounter = 0;\;对于WPF和C#来说非常新,但在我看来下面(MainWindow.xaml)就是这个类被实例化的地方:
<Window x:Class="CompositionTargetSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Composition Target Rendering Sample"
Width="768"
Height="512">回到MainWindow.xaml.cs,在MainWindow类之外,我想引用在MainWindow.xaml中实例化的对象的_frameCounter字段,但不知道如何寻址该MainWindow对象。
发布于 2013-10-29 13:45:31
可以使用以下命令访问您的字段
Application.Current.MainWindow._frameCounter发布于 2013-10-29 10:18:18
试试这个:Application.Current.MainWindow._frameCounter
Application.MainWindow MSDN
发布于 2021-11-18 07:10:05
这对我很管用
Window.GetWindow(App.Current.MainWindow) as MainWindowhttps://stackoverflow.com/questions/19647375
复制相似问题