我可以在运行时更改的Silverlight外的浏览器设置? [英] Can I change Silverlight out-of-browser settings at runtime?

查看:145
本文介绍了我可以在运行时更改的Silverlight外的浏览器设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在各种配置安装OOB SL5应用一个单一的代码库。根据在运行时配置(通过初始化参数选择)我想更新OOB设置(标题,窗口标题)之前进行安装。看来,唯一的办法就是通过在编译时OutOfBrowserSettings.xml文件(或项目设置UI)。我缺少的东西,或者这只是事情是这样的?

I have a single codebase that can install an OOB SL5 app in various configurations. Based on the configuration at runtime (selected by init parameters) I would like to update the OOB Settings (title, window title) prior to performing the install. It appears that the only way is through the OutOfBrowserSettings.xml file (or the Project Settings UI) at compile time. Am I missing something or is this just the way it is?

推荐答案

根据MSDN你可以做到这一点。

According to MSDN you can do that.

要配置外的浏览器支持现有的应用程序无需重新编译,配置XML添加到体现在现有的.xap文件。要做到这一点,从下面的示例代码复制Deployment.OutOfBrowserSettings属性元素到清单文件,然后更新值。

To configure an existing application for out-of-browser support without recompiling, add the configuration XML to the manifest in an existing .xap file. To do this, copy the Deployment.OutOfBrowserSettings property element from the following example code into the manifest file, and then update the values.

作为一种替代的设计师,你可以通过填充如下面的示例所示清单文件(AppManifest.xml在属性或我的项目文件夹)指定外的浏览器设置。默认情况下,构建使用清单模板生成的应用程序清单。然而,模板XML是简单在Visual Studio中使用

As an alternative to the designer, you can specify the out-of-browser settings by populating the manifest template (AppManifest.xml in the Properties or My Project folder) as shown in the following example. By default, the build uses the manifest template to generate the application manifest. However, the template XML is simpler to use in Visual Studio.

来源:
http://msdn.microsoft.com/en-us/library/dd833073(v = VS.95)的.aspx

记住,在* .xap文件是一个简单的拉链。所以,你可以提取它,修改,然后再次压缩了。看起来很简单实现自动化。

Remember, that the *.xap file is a simple zip. So you can extract it, modify, and then zip it again. Seems pretty simple to automate.

您还可以更改应用程序运行时(的头衔,我不知道如何更改图标或描述,但我认为, woulndt通过实现自己的镶边的窗口有意识反正)。对于执行样本按照

You can also change the title of the application at runtime (i don't know how to change the icon or description, but i think that woulndt have sense anyway) by implementing your own chrome window. For sample implementation follow this

要本地化的标题,你就必须改变所有权的价值,具有约束力,并绑定到你的资源(所有的代码为样本项目的某些定制从上面的链接):

To localize title you would have to change the value of title, to binding, and bind it to your resource(all code is some customization of sample project from link above):

MainPage.xaml中:

MainPage.xaml:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Silverlight4.OOB.ChromelessWindow.Demo" x:Class="Silverlight4.OOB.ChromelessWindow.Demo.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" MinWidth="400" MinHeight="300">
<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>        
    <Border BorderBrush="Black" BorderThickness="1" Margin="0,-25,0,0" Grid.Row="1"/>
    <local:ControlBar x:Name="ucControlBar" VerticalAlignment="Top" Title="{Binding Source={StaticResource resxWrapper}, Path=Title}"></local:ControlBar>
    <Border BorderBrush="Black" BorderThickness="1" CornerRadius="10" Grid.Row="1" Margin="10">
        <Border.Background>
            <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                <GradientStop Color="#FFFDC97A"/>
                <GradientStop Color="White" Offset="0.5"/>
                <GradientStop Color="#FFFDC97A" Offset="1"/>
            </LinearGradientBrush>
        </Border.Background>

    </Border>
    <ComboBox SelectionChanged="ComboBox_SelectionChanged" Grid.Row="1" Height="20">
        <ComboBoxItem Content="pl-PL" />
        <ComboBoxItem Content="en-GB" />
    </ComboBox>
    <TextBlock x:Name="txtTitle" HorizontalAlignment="Center" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="32" Text="Silverlight 4 Custom Out-Of-Browser Window Demo" Margin="10" TextAlignment="Center" Foreground="#FF5A098F"/>
    <TextBlock x:Name="txtInfo" HorizontalAlignment="Center" Grid.Row="1" TextWrapping="Wrap" Text="You are running inside Browser Window" VerticalAlignment="Bottom" Margin="10" FontSize="24" TextAlignment="Center"/>        
</Grid>



补充文件ResourceMock.cs:

Added file ResourceMock.cs:

 public class ResourceMock:INotifyPropertyChanged
{
    public string Title
    {
        get
        {
            MessageBox.Show(Thread.CurrentThread.CurrentCulture.Name);
            switch (Thread.CurrentThread.CurrentCulture.Name)
            {
                case "en-GB": return "English"; break;
                case "pl-PL": return "Polish"; break;
                default: return "default";
                    break;
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    public void firePropertyChanged(string property)
    {
        OnPropertyChanged(property);
    }
}



MainPage.xaml.cs中:

MainPage.xaml.cs:

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();

        if (App.IsRunningOOBWithPermission)
        {
            txtInfo.Text = "You are running outside Browser Window.";
        }
        else
        {
            txtInfo.Text = "You are running inside Browser Window.";
        }
    }

    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var cultrue = (e.AddedItems[0] as ComboBoxItem).Content.ToString();
        try
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultrue);
            var res = App.Current.Resources["resxWrapper"] as ResourceMock;
            res.firePropertyChanged("Title");
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }


}

App.xaml中:

App.xaml:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         x:Class="Silverlight4.OOB.ChromelessWindow.Demo.App"
         xmlns:loc="clr-namespace:Silverlight4.OOB.ChromelessWindow.Demo"
         >
    <Application.Resources>
       <loc:ResourceMock x:Key="resxWrapper"></loc:ResourceMock>
    </Application.Resources>
</Application>

这是非常简单的示例,展示,你可以在运行时更改标题。林assmuming,如果您有标题暴露为绑定属性,那么你就会知道如何实现自己的定位。

This is very simple sample, to show, that you can change the title at Runtime. Im assmuming, that if you have title exposed as bindable property, then you will know how to implement your own localization.

有关上面的示例工作,你需要添加EN-GB; PL-PL到SupportedCultrues标签,在项目文件(* .csproj的)

For the above sample to work, you need to add "en-GB;pl-PL" to the SupportedCultrues tag, in the project file (*.csproj).

这篇关于我可以在运行时更改的Silverlight外的浏览器设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆