Closed anders-eriksson closed 5 years ago
OK, I found out my error. GetData("id) where id is the name of the json file.
Is there anyway to get the filename?
Hey Anders! Should the splash screen have the same size and location as the main window? If so, instead of digging through the properties manually, you can use Jot to apply settings by using the same Id() for the splash window and your main window. Jot will then use the same settings for both.
e.g.
Tracker.Configure<MyMainWindow>()
.Id(w => "main window")
.Properties(w => new { w.Height, w.Width, w.Left, w.Top, w.WindowState })
.PersistOn(nameof(Window.WindowClosed))
Tracker.Configure<MySplashScreen>()
.Id(w => "main window")
.Properties(w => new { w.Height, w.Width, w.Left, w.Top})
Hello aniakic, Unfortunately the window sizes and positions are different. So I need to get the values from the json file and calculate where the splash windows should be. The "problem" is to get the name of the json file. I can't find any public function that returns the filename...
I see. I assume you want to center the splash screen relative to where the main window is supposed to be?
About the filename, I just pushed an update that exposes a method that will give you the store name. The update is both here on GitHub and on NuGet (v2.0.3).
Here's an example of how to use it to get the stored data for your main window.
public MainWindow()
{
InitializeComponent();
// some config for your MainWindow
tracker.Configure<MainWindow>()
.Id(w => "xxx")
.Properties(w => new { w.Top, w.Left, w.Height, w.Width })
.PersistOn(nameof(Window.Closed));
// Here's the new part:
// 1. get the tracking config for MainWindow
var cfg = tracker.Configure<MainWindow>();
// 2. get the storeId of this window (do you have the window instance at this point? If not, you can use a throwaway window instance with the same Name)
var storeId = cfg.GetStoreId(this);
// 3. getting the values for the specified storeId
var data = tracker.Store.GetData(storeId);
}
Also note that I made another change: including the type name in Id() so that the target type is part of the identifier. This changes the object ids so Jot will not pick up your old data from the previous version. If you want to exclude the typeName, there's a parameter for that in Id() in which case it should pick up any previously stored data you have.
Hello Anakic,
Yes I want the center of the splash windows relative to where the main window is supposed to be! It doesn't look good if the splash window is on the center of the screen and the main window is off center...
The new version of Jot worked perfectly! Just a small detail in the code you supplied. The last line should be
var data = tracker.Store.GetData(storeId);
Thanks for the update and for creating a really useful piece of code! // Anders
Thanks for using it!
I need to get the saved window positions (Top, Width, Height, Left, WindowState) to position a Splash windows before the main window is shown.
I have tried:
But the returned dictionaries are empty. The json file looks like this
I rather not read the json file directly, so what am I doing wrong and how do it right?