How to Put a Logo in the Starting of the LS Application
-
13. března 2012 8:30
I Don't want the Splash Screen.
I want the Static Image to be Displayed at the Background of The Application Like This....
Well Beth had Explained in her Blog But that was for Beta 1. It Doesn't Work For Me.
Well Any one can tell how get this type of Image in LS.
Sharad Soni
Všechny reakce
-
13. března 2012 9:20
Home screen: (add image property on home screen)
namespace LightSwitchApplication { public partial class HomeScreen { partial void HomeScreen_InitializeDataWorkspace(List<IDataService> saveChangesTo) { this.LogoImage = ImageHelper.GetImageFromResourcesByName("logo_image.png"); } }ImageHelper class:
public class ImageHelper { public static byte[] GetImageFromResourcesByName(string fileName) { var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream("LightSwitchApplication.Resources." + fileName); return GetStreamAsByteArray(stream); } public static byte[] GetStreamAsByteArray(Stream stream) { if (stream != null) { var streamLength = Convert.ToInt32(stream.Length); var imageData = new byte[streamLength]; stream.Read(imageData, 0, streamLength); stream.Close(); return imageData; } return null; } }For your image select embedded resource for build action and use appropriate namespace (which is LightSwitchApplication by default, but if you add it to some folder include folder name ).
-
13. března 2012 9:53
I don't want the image in the specific Screen. I actually want that ,
When you run your application the logo appears on the background of the main window area. As shown in the above Image.
Sharad Soni
-
13. března 2012 22:51
The most flexible approach to controlling this sort of thing is to use a custom shell and theme. But barring that, you can use this sort of approach:
1. In Solution explorer, switch to File Mode and add a folder in the Client subproject called Resources
2. Add your logo image there... in this example I've named it MyLogoBackgroundImage.jpg
3. In the properties of the image, set "Build Action" to "Embedded Resource"
4. In whichever screen of your LightSwitch project that is set as the startup screen, click "Write Code" and choose the Created method... add this code there:
this.FindControl("ScreenLayout").ControlAvailable += (s, e) => { var image = new System.Windows.Media.Imaging.BitmapImage(); image.SetSource(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(Application.Current.Details.Name + ".Resources.MyLogoBackgroundImage.jpg")); var imageBrush = new System.Windows.Media.ImageBrush(); imageBrush.ImageSource = image; imageBrush.Opacity = .5; // or whatever opacity you prefer var current = (e.Control) as System.Windows.DependencyObject; var last = current; while (current != null) { var frameworkElement = current as System.Windows.FrameworkElement; if (current is System.Windows.Controls.Grid && frameworkElement != null && frameworkElement.Name == "TemplateTop") { break; } last = current; current = System.Windows.Media.VisualTreeHelper.GetParent(current); }; var border = last as System.Windows.Controls.Border; if (border != null) border.Background = imageBrush; };
This code works in the VS 11 Beta... if you're using Lightswitch 2011, change the FindControl line to use the name of some other control on your screen instead of ScreenLayout- Upravený Jewel Lambert 13. března 2012 22:51
-
14. března 2012 12:40
Thanks Jewel,
Watching Your Answer seems to Solve my Problem. But Sorry to say that i know only VB and not C#.
Can you give me the VB Code. And another Thing i want to ask is that i had not set any startup screen.
And I am Using LightSwitch 2011 and not Beta Version.
Sharad Soni
-
14. března 2012 16:09
Hi Jewel,
I Tried to convert the C# Code into VB. But at some Point I Stuck...
That is,
this.FindControl("ScreenLayout").ControlAvailable += (s, e) => {
I not am knowing how to Convert this Function into VB and i think "s,e" are the Parameters...
If you Help to convert into VB i can Move Ahead.
Sharad Soni
-
14. března 2012 16:51
Okay, your Created sub will look something like this:
Private Sub MyScreen_Created() AddHandler Me.FindControl("SomeKnownControlOnScreen").ControlAvailable, AddressOf InsertBackgroundImage End Sub Private Sub InsertBackgroundImage(s As Object, e As ControlAvailableEventArgs) Dim image = New System.Windows.Media.Imaging.BitmapImage() image.SetSource(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyLogoBackgroundImage.jpg")) Dim imageBrush = New System.Windows.Media.ImageBrush() imageBrush.ImageSource = image imageBrush.Opacity = 0.5 ' or whatever opacity you prefer Dim current = TryCast(e.Control, System.Windows.DependencyObject) Dim last = current While current IsNot Nothing Dim frameworkElement = TryCast(current, System.Windows.FrameworkElement) If TypeOf current Is System.Windows.Controls.Grid AndAlso frameworkElement IsNot Nothing AndAlso frameworkElement.Name = "TemplateTop" Then Exit While End If last = current current = System.Windows.Media.VisualTreeHelper.GetParent(current) End While Dim border = TryCast(last, System.Windows.Controls.Border) If border IsNot Nothing Then border.Background = imageBrush End If End SubFor some reason in VB LightSwitch projects, GetManifestResourceStream doesn't use the same path, so I had to fix that as well.
Not sure what the best way to approach this would be if you don't want to have a startup screen...
- Označen jako odpověď Dino HeModerator 20. března 2012 2:54