LightSwitch登录界面如何设置背景

 LightSwitch中登录窗口是系统自动提供的,同时不支持自定义登录接口,程序一运行,就显示一个大白屏,中间是登录名,密码及一个按钮,这个真的非常难看。对于登录后的界面(应用一些皮肤样式),真的难于忍受。自己来动手美化一下吧。

 

将LS切换到文件模式下,进入到client项目,找到UserCode下的Application.cs,在里面添加如下代码,原理是通过对象引用找到系统内置登录窗口中的容器对象,强行植入背景。代码如下:

 

   
using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using System.Windows.Controls;
using System.Reflection;
using Microsoft.LightSwitch.Runtime.Shell.Internal.Implementation; 

    public partial class Application
    {

        Frame rootFrame = null;
        partial void Application_Initialize()
        {
            
            Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =>
            {
                rootFrame = ((Page)((ContentPresenter)System.Windows.Application.Current.RootVisual).Content).Content as Frame;
                if (rootFrame != null)
                    rootFrame.Navigated += new System.Windows.Navigation.NavigatedEventHandler(rootFrame_Navigated);
            });
        }
        void rootFrame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.Content is LoginPage)
            {
                // prepare image, that is laying in the Resources folder as Embedded Resource
                System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage();

                image.SetSource(Assembly.GetExecutingAssembly().GetManifestResourceStream(this.GetType(), "bg.png"));
              
                Image mylogo = new Image() { Source = image, Stretch = System.Windows.Media.Stretch.Uniform };
                mylogo.SetValue(Grid.ColumnSpanProperty, 5);
                mylogo.SetValue(Grid.RowSpanProperty, 7);
                 mylogo.Stretch = System.Windows.Media.Stretch.Fill;//拉伸
                // add image
                Grid grid = ((LoginPage)e.Content).Content as Grid;
                grid.Children.Insert(0, mylogo); // not Add, for background
                rootFrame.Navigated -= rootFrame_Navigated;
            }
        }
}

运行一下。看一下效果


背景图在QQ SL版基础上修改了一下。 大笑
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值