WPF - 如何获取 MainWindow 实例? [英] WPF - How do I get the MainWindow instance?

查看:38
本文介绍了WPF - 如何获取 MainWindow 实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MainWindow.xaml.cs 中有这个:

I have this in MainWindow.xaml.cs:

public partial class MainWindow : Window
{
    public double _frameCounter = 0;\;

对 WPF 和 C# 非常陌生,但在我看来,下面的 (MainWindow.xaml) 是实例化此类的地方:

Very new to WPF and C#, but the below (MainWindow.xaml) appears to me to be where this class is being instantiated:

<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 对象.

Back in MainWindow.xaml.cs, outside of the MainWindow class, I want to reference the _frameCounter field of the object instantiated in MainWindow.xaml, but don't know how to address that MainWindow object.

推荐答案

您可以使用

Application.Current.MainWindow._frameCounter

这篇关于WPF - 如何获取 MainWindow 实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆