WPF SplashScreen using external image - c#

I need to make my SplashScreen show image from hard drive (since i will use several images, which may be changed outside of project). But WPF SplashScreen accepts only resource files, present in this or another assembly.
So, how can i solve it? Maybe, there is some way to create temporary resource file during runtime?

The best way to accomplish this goal is to not use the splash screen feature at all.
Create a new XAML window and size it to the size you want your splash screen to be. You can then use to reference the image you'd like to. This can also be done from code-behind now when loading.
When you're ready, have your main window launch the splash screen as the first thing it does. Let it load everything you need, and then show the main window and close the splash screen window.
This way you have full control over your "splash screen" because it's just another window that you're loading.
The one downside of this is that it might have a very small (.5 second or so) delay because WPF has to load before the window can show. An actual splashscreen is not WPF so it will show immediately. This has never been an issue for me.

I don't think this can be done as you want, however, it could be possible to create a separate assembly, which can be changed out whenever you want, which would contain the resource, using:
SpashScreen(Assembly, string);

Related

How to create a window within a UWP app to enter in detail/properties information

So I'm sure there's an easy way to do this but I don't know the exact terminology for what I'm wanting.
Essentially in my C# xaml uwp app I have a couple objects that need to have details added to them, kind of like file properties. I have a button that I would like to open up another window (still part of the app), just to enter in the properties. I just don't know the terminology to look up what this window would be called or find documentation for it. So the exact same as when you're in a file browser and you open the properties of a file; it opens in a little extra window that you can drag around.
I don't want to be able to use the main window while the properties window is open, and of course they need to be able to transfer data between one another.
In my previous apps I've simply made a grid that appears over everything else in the middle of the app and shaded the outer area. A workaround as I didn't know how to do this.
Can anyone help me out?
Maybe you can use Dialog refer to https://learn.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/dialogs-and-flyouts/dialogs.
Dialog controls are modal UI overlays that provide contextual app information. They block interactions with the app window until being explicitly dismissed. They often request some kind of action from the user.

WPF C# Application does not show loading gif

I want to add a gif into the program that will be shown during init of the actual app, as a splashscreen for WPF only takes static imgs(png etc).
I need to take a different route, i was hoping anyone could point me in the correct way.
Im figuring that i need to create a new thread for a form(so the gif doesn't freeze) and then displaying it somehow.
Help or example code would be appreciated, cheers guys
You should do various steps:
Install this library, that allow you put gifs in Image
elements.
In the Window where you put your gif, set properties
AllowsTransparency="True", Background="Transparent" and WindowStyle="None", and inside this window put your Image with the gif.
In the loaded event of the window, perform your code that initialize your app in a Task. In this way, your app will not freeze.
After initialization, show your main window y hide the window that
contains your gif.
You also must set in the App.xaml, your property ShutdownMode="OnLastWindowClose".
I leave a project with this approach (check MainWindow and App.xaml)

UWP Customized Splash Screen Sample

I want to create a splash screen in UWP. I want do more than just center an image in the screen. I thought it would be a lot more straight forward. I saw these articles:
https://learn.microsoft.com/en-us/previous-versions/windows/apps/hh868191(v=win.10)
https://code.msdn.microsoft.com/windowsapps/Splash-Screen-in-Universal-42c0b57a
When I first opened up this sample, I thought that it worked... But, it doesn't actually do anything. It's actually just a furphy. If you look carefully at the screen, it actually just shows an image (defined in the manifest) for a second or two as the app is starting up, and then when the app is loaded, it switches to the extended screen with a progress ring. I've seen samples where people turn on the splash screen image, but that's not want I need to achieve. Part of the problem is that UWP app startup time is terrible even on fast machines. Even blank apps with nothing in them take several seconds to start up.
Is there a UWP sample floating around that actually a) cuts out the splash image from the manifest, and b) allows us to replace it with something else?
Note: I do not wish to remove the splash screen. I want to customize it.
The main splash screen (centered splash screen image defined in the package.appxmanifest) will always be displayed unless you make it optional - while even in this case it will be shown to the user when the app doesn't load immediately.
To make the splash screen optional, you have to open the manifest file as XML, add the following namespace declaration:
<Package
...
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5">
And then add the uap5:optional attribute to your splash screen:
<uap:SplashScreen ... uap5:Optional="true" />
You can implement an extended splash screen, which is described in the articles you linked. If you postpone all initialization for the extended splash screen, it is quite likely that the optional default splash screen will not display at all.
However, although the samples only show the same image with progress ring, you can put any content you want on the extended splash screen, you are in full control of it because it is a normal Page.

C# launch form when images fully loaded

I'm making C# application design with images, but when I launch it, I see loading images (~1sec), so how to make simple loader, when images (background, logo, etc..) fully loads, to show my app? I know it's possible but I don't know how to. Thanks so much!
This sounds like standard behaviour. The controls get painted one by one in z-order and if one is slow the rest may appear to flicker.
You could try double buffering the whole form as shown here:
How to fix the flickering in User controls
Alternatively you could suspend the layout while everything is drawn and resume it afterwards:
How do I suspend painting for a control and its children?

WPF Application starts up too slowly

I have problems with my current application which is developed in C# with WPF. The application consists of different flowcharts each contained in its own separate window.
At start-up all flowchart classes are instantiated and initialized in their window. Then the windows are made invisible and the flowchart menu appears.
With each new flowchart the application start up gets slower. The window initialization seems to consume a lot of time.
How could I approach this problem?
I thought of initialization when first needed or background initialization.
Note: I forgot a very important fact: The flowchart menu is created based on the other flowcharts, since every single flowchart is rendered as an image in order to display a thumbnail menu button. This is the problem which brough me to the performance impact anyway.
You have many approaches to this problem.
First, you have to remove the initialization from the c'tor.
Where to move it?
Either to Window_onLoad event, this way the app will first loaded and then start initializing the flow charts (using a new thread will avoid UI freeze).
Or once the user selects the required flow chart from the menu, you show the window and start initializing the inner flow chart, display a nice "loading.." animation while busy, and show the flow chart once you done.
I'd prefer the second approach, init each object when it's needed.
Edit:
Since you have to render the thumbs based on the flowcharts, i would do the following:
Move the flowcharts init to the main window Loaded event, and init each flowchart on a different thread, while busy display a nice "please wait.." animation. This way the main app window appears, the user see that the app is loading, your thumbs will be created simultaneously therefore loading time will be reduced. Once all the thumbs created, hide the animation.
Don't instantiate all the flowchart classes before you load the main window.
As a first approach I'd go with initialisation when needed.
If this proves to be unpopular as people don't like waiting then go for a background initialisation with the most popular or most recent flowchart instantiated first. This will be right most of the time so the user won't have to wait.
If you need to have a thumbnail of the flowchart then why not save the thumbnail from when the flowchart was last rendered and use that? So, when the flowchart is created first saved save a thumbnail at that point. Then when you populate the list pull that out of the database/off disk and render that.
Nobody's mentioned profiling yet, but why not just try (the last paragraph of) this?
You will easily see the dominant reason for the long time being taken.
Chances are, it's something fairly trivial that you can easily fix.
If you want more of an explanation, look here.

Categories