Lightswitch添加背景图片

来源:互联网 发布:淘宝促销管理找不到 编辑:程序博客网 时间:2024/04/28 05:44

1,首先引用2个dll文件

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\LightSwitch\1.0\Client\Microsoft.LightSwitch.Client.Internal.dll

c:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Windows.Controls.Navigation.dll

2.在Application中添加如下代码即可

 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(), "Resources.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;//拉伸

                Grid grid = ((LoginPage)e.Content).Content as Grid;

                grid.Children.Insert(0, mylogo); // not Add, for background
                rootFrame.Navigated -= rootFrame_Navigated;
            }
        }
      
    }

3.将图片添加到Resources中,发布后就可以看到效果了

 

原创粉丝点击