How to determine that UserControl has been loaded completely?
I have some UserControls with images and media files from another server bound like that:
<Image Source="{Binding Image}" />
I would like to know when all my images are downloaded and ready to be shown.
I've noticed an event ImageLoaded, and probably I can listen to it on all of my Image controls. Isn't there a better way to do that?
The class FrameworkElement contains a public event called "Loaded", so naturally all classes derviving from it (UserControl class) expose it as well.
MSDN
The question would be : Are you downloading your images ? (This can be after loading of the control Check here) Or are you embedding your images in the project? They'll be a part of the .xap file that's downloaded when you launch your application.
You can add an event handler to that event to execute code when the said event occurrs. Hope that helps.
Related
I've got a DotNetBrowser instance defined in a XAML file
<Grid>
<wpf:WPFBrowserView x:Name="BrowserView"></wpf:WPFBrowserView>
</Grid>
The application is used by multiple people, which is causing issues due to the issue discussed here:
Chromium profile directory is already used/locked by another browser
Is it possible to use XAML to define the browser control and still assign a custom context to the browser instance?
Is it possible to use XAML to define the browser control and still assign a custom context to the browser instance?
No, I am afraid it's not.
The Browser property of the WPFBrowserView class doesn't have a public setter so you must create the custom Browser and the BrowserContext programmatically:
BrowserContextParams params1 = new BrowserContextParams("C:\\my-data1");
BrowserContext context1 = new BrowserContext(params1);
Browser browser1 = BrowserFactory.Create(context1);
XAML doesn't support anything like calling BrowserFactory.Create(context1).
Unfortunately, the custom BrowserContext can be configured only if the Browser and WPFBrowserView were created from the source code.
The possible approach is to wrap WPFBrowserView and its non-default initialization into a custom control that manages instantiating and disposal of the WPFBrowserView, make this control expose all the necessary properties and then insert it into your XAML.
I have a Prism 4.0 enabled WPF application that uses RequestNavigate extensively, and it is working well. I have a scenario where I would like to render part of my UI to an image and store it for later use from a Windows service. I already know how to use RenderTargetBitmap to generate the image, but whenever my code tries to call RequestNavigate, nothing happens. I am calling the bootstrapper, so I would expect that all of the types are loaded, but it just is not working. Can anyone tell me if this should even be possible? Is there anything inherent to RequestNavigate that prevents it from working when there is no UI present?
Individual steps:
First, I call Run on my MefBootstrapper. This loads up all of the assemblies into the AggregateCatalog.
Then, I use MEF CompositionContainer.GetExportedValue to create a WPF UserControl that has a single ContentControl that is assigned a RegionManager.RegionName. This always creates the initial UserControl just fine.
Finally, I call MefRegionManager.RequestNavigate with the region name on my UserControl and the path to another UserControl that I want it to load. This fails to load the UserControl that I am attempting to navigate to.
If these are the only steps that I follow, then the final UserControl fails to load whether I am running from a Windows Service or from within my WPF application. However, if I call SetRegionManager to explicitely add the region from my host UserControl before calling RequestNavigate, then the last UserControl will load properly, as long as the code is run from within the WPF application. If this same code is run from my Windows service, then it still does not load.
RequestNavigate is exactly that, a request to navigate to a loaded (but inactive) region. It won't do any loading itself. You need to separately manage the loading of views (including views within views).
If your nested user control is only over loaded within the parent, and you don't need to manage it at runtime, then you can use ViewDiscovery. You register all the views in advance, and then when the region is created, it looks for (and loads) all the nested views. If you need to manage the views at runtime, switch them in and out, etc, then you can use ViewInjection.
For ViewDiscovery, in the Initialize method of the ModuleInit class in your module, insert the following line:
_regionManager.RegisterViewWithRegion("RegionNameOfYourNestedControl",
() => this.container.Resolve<NestedUserControl>());
Then when your region is loaded, the NestedUserControl will automatically be loaded into your ContentControl (region).
For more detail on ViewDiscovery, ViewInjection and UI composition, have a read of the prism documentation
In my wpf project i have created a folder called practice, in that folder i added a window, now i want to run that window, so in app.xaml file i set the startup uri to foldername.window.xaml but it is saying build action property is not set to resource.
for that i setted build action property to resource. Now this time that it is showing error message initialized componenet doesn't exist in the current context.
Can you tell me what properties we need to set when we create separate folders in wpf project and that folders contains windows or pages. and How to access those pages in other pages or in App.Xaml file startupUri Property.
When you have folders in your project structure, you should use a "/" not a ".", so it's foldername/window.xaml.
(I hope it's not actually called window.xaml by the way. That's a confusing name for a type in a WPF project, because there's a built in type called Window.)
Setting the build action to Resource will make matters worse: not only were you using the wrong name, you've now changed the build action to the wrong one for XAML. The correct build action for a .xaml file is usually Page. (App.xaml is an exception to that rule.) The Page build action causes the page to be compiled into a binary representation (known as BAML), and that binary format can then be loaded either by the call to InitializeComponent in the codebehind, or through Application.LoadComponent.
Setting the build action to Resource will just embed a copy of the XAML source directly in the project, which won't help you - you can't work with XAML in that form if you want to have a codebehind file. (Not in WPF, anyway. It's different in other XAML-based frameworks such as WinRT.)
Since Page is the default build action for a newly-added window, you don't actually need to set any properties at all. You just need to use / for folder boundaries.
If the XAML is inside any Folder the startup url will be defined as below.
This is how it will defined.
I have some icons in my WPF project to make the application more user friendly. WPF shows all icons on my computer but when I run the app on other computers it will show some of icons but not all of them. How can I fix it?
Update:
<Image Source="Office/Add-Female-User.ico" Stretch="None" />
I'm sure that all images are accessible because some of them are visible.
You are referencing your images (in your image controls) as Content not Resource. I suspect the problem is your images aren't copied to the output dir. View properties on missing image files and set build action to Content and Copy to output dir to Copy if newer.
For resource referencing see http://msdn.microsoft.com/en-us/library/aa970069.aspx.
Im trying to play a wmv video on the home page of a Silverligh Navigation Application, but it won't start playing. I've stored the file in the clientbin folder and changed the build action to resource.
<Canvas Name="Holder" Width="350" Height="220" Background="Black">
<MediaElement Name="Video" AutoPlay="True" Volume="100" Source="vid.wmv"/>
</Canvas>
Additionally I've tried making a button and add a Video.Play() method but still no luck... When I play the file using WMP it works perfect.
Any ideas?
Thanks
There's quite probably an exception being thrown while attempting to load the video. Add a handler to the MediaFailed event of your MediaElement and see what the exception you get from inside the ExceptionRoutedEventArgs parameter is.