I have this in MainWindow.xaml.cs:
public partial class MainWindow : Window { public double _frameCounter = 0;\;
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">
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.
Just delete the StartupUri="MainWindow. xaml" attribute in App. xaml , Add a Program class to your project containing a Main method, and then go to the project properties and set the startup object to YourAssemblyName.
If you look at App. xaml class of your WPF application, you will see the following XAML code. Here the StartupUri sets the startup Window of an application. If you want to change the Startup window to some other window, just change this value.
For a WPF standalone application that is generated in Visual Studio using the New Project wizard, the entry point for the application is the Main function, defined in App. g. cs (generated code). In the default project, this is the public static void App.
The Main window is the main way to access other windows, load and save files, control trajectory playback, change various global program settings, access help, and to quit the program. Many of these actions can also be performed with the menu shortcut keys described in Table 5.3.
You can access your field with
Application.Current.MainWindow._frameCounter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With