|
|
Demonstrated issues:
Prerequisities:
Steps:
public class BrushRandomizer
{
private static readonly Random random = new Random();
public Brush RandomSolidColorBrush
{
get
{
Color c = new Color
{
A = 255,
R = (byte)random.Next(256),
G = (byte)random.Next(256),
B = (byte)random.Next(256)
};
return new SolidColorBrush(c);
}
}
}
<UserControl.Resources>
<local:BrushRandomizer x:Name="BrushRandomizer"/>
</UserControl.Resources>
<UserControl
x:Class="WebPageIntegration.MainPage"
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:WebPageIntegration"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
>
<Border
Background="{Binding RandomSolidColorBrush, Source={StaticResource BrushRandomizer}, Mode=OneWay}"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="5"
>
<TextBlock
x:Name="MainTextBlock"
Foreground="{Binding RandomSolidColorBrush, Source={StaticResource BrushRandomizer}, Mode=OneWay}"
Text="Something"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
</Border>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<p>This is an HTML test page for the WebPageIntegration Silverlight application.</p>
<table cellpadding="5" cellspacing="5" style="width:100%;">
<tr>
<td>
<object width="100%" height="50"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2">
<param name="source" value="WebPageIntegration.xap" />
</object>
</td>
<td>
<object width="100%" height="50"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2">
<param name="source" value="WebPageIntegration.xap" />
</object>
</td>
</tr>
<tr>
<td>
<object width="100%" height="50"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2">
<param name="source" value="WebPageIntegration.xap" />
</object>
</td>
<td>
<object width="100%" height="50"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2">
<param name="source" value="WebPageIntegration.xap" />
</object>
</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>TestJSPage.html</title>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript">
function embedSilverlight(parentElement, pluginId, userContext) {
var altHtml = pluginId == "sl1" ? null : "<!--not installed-->";
return Silverlight.createObject("WebPageIntegration.xap",
parentElement, pluginId,
{
width: "200", height: "50",
background: "white", alt: altHtml,
version: "3.0.40624", autoUpgrade: "true"
},
{ onError: onSLError, onLoad: onSLLoad },
"myParam=myValue", userContext);
}
function onSLLoad(plugIn, userContext, sender) {
window.status += plugIn.id + " loaded into " + userContext + ". ";
}
function onSLError(sender, args) {
// Display error message.
}
</script>
</head>
<body>
<table>
</table>
</body>
</html>
<script>
window.onload = function() {
document.getElementById("sl1Host").innerHTML = embedSilverlight(null, "sl1", "row1");
}
</script>
<tr>
<td>- 1 -</td>
<td id="sl1Host" />
</tr>
<tr>
<td>- 2 -</td>
<td id="sl2Host">
<script type="text/javascript">
embedSilverlight(document.getElementById("sl2Host"), "sl2", "row2");
</script>
</td>
</tr>
<tr>
<td>- 3 -</td>
<td id="sl3Host">
<script type="text/javascript">
Silverlight.createObject(
"WebPageIntegration.xap",
document.getElementById("sl3Host"),
"sl3",
{
width: "200", height: "50",
background: "white", alt: "<!--not installed-->",
version: "3.0.40624.0"
},
{
onError: onSLError,
onLoad: onSLLoad
},
"myParam=myValue3",
"row3");
</script>
</td>
</tr>
<tr>
<td>- 4 -</td>
<td id="sl4Host">
<script type="text/javascript">
Silverlight.createObjectEx({
source: "WebPageIntegration.xap",
parentElement: document.getElementById("sl4Host"),
id: "sl4",
properties: {
width: "200",
height: "50",
background: "white",
alt: "<!--not installed-->",
version: "3.0.40624.0"
},
events: {
onError: onSLError,
onLoad: onSLLoad
},
initParams: "myParam=myValue4",
context: "row4"
});
</script>
</td>
</tr>
private void Application_Startup(object sender, StartupEventArgs e)
{
const string paramKey = "myParam";
string paramValue = "";
if (e.InitParams.ContainsKey(paramKey))
{
paramValue = e.InitParams[paramKey];
}
this.RootVisual = new MainPage(paramValue);
}
public MainPage(string paramValue)
{
InitializeComponent();
MainTextBlock.Text = paramValue;
}
<Border
Background="{Binding RandomSolidColorBrush, Source={StaticResource BrushRandomizer}, Mode=OneWay}"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="5"
>
<StackPanel
VerticalAlignment="Center"
HorizontalAlignment="Center"
>
<TextBlock
x:Name="MainTextBlock"
Foreground="{Binding RandomSolidColorBrush, Source={StaticResource BrushRandomizer}, Mode=OneWay}"
Text="Something"
VerticalAlignment="Center"
HorizontalAlignment="Center"
/>
<StackPanel
Orientation="Horizontal"
>
<TextBox
x:Name="SendTextBox"
Width="120"
/>
<Button
x:Name="SendButton"
Content="Send"
Click="SendButton_Click"
/>
</StackPanel>
</StackPanel>
</Border>
<script type="text/javascript">
function MyJSFunction(param) {
alert(param);
}
</script>
private void SendButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
HtmlPage.Window.Invoke("MyJSFunction", SendTextBox.Text);
}
[ScriptableMember]
public void SetText(string text)
{
MainTextBlock.Text = text;
}
public MainPage(string paramValue)
{
InitializeComponent();
MainTextBlock.Text = paramValue;
HtmlPage.RegisterScriptableObject("MainPage", this);
}
<script type="text/javascript">
function DoIt(controlId, param) {
var slControl = document.getElementById(controlId);
slControl.Content.MainPage.SetText(param);
}
function MyJSFunction(param) {
DoIt("sl1", param);
DoIt("sl2", param);
DoIt("sl3", param);
DoIt("sl4", param);
}
</script>
<Border
Background="Yellow"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="5"
Margin="10"
>
<TextBlock
Text="CustomSplashScreen is working now!"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="18"
FontWeight="Bold"
/>
</Border>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<p>This is an HTML test page for the CustomSplashScreen Silverlight application.</p>
<object width="100%" height="80%"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2">
<param name="source" value="CustomSplashScreen.xap" />
</object>
</body>
</html>
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Rectangle
x:Name="Border"
StrokeThickness="1"
Stroke="LightGray"
Height="20"
Width="200"
/>
<Rectangle
x:Name="Bar"
Fill="LightGray"
Height="20"
Width="0"
/>
<TextBlock
x:Name="Text"
Canvas.Left="0"
Canvas.Top="2"
Width="200"
TextAlignment="Center"
/>
</Canvas>
<object width="100%" height="80%"
id="theApp"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2">
<param name="source" value="CustomSplashScreen.xap" />
<param name="splashscreensource" value="CustomSplash.xaml"/>
<param name="onSourceDownloadProgressChanged" value="onSourceDownloadProgressChanged" />
</object>
<script language=javascript>
function onSourceDownloadProgressChanged(sender, eventArgs) {
var myHost = document.getElementById("theApp");
var bar = myHost.content.findName("Bar");
var border = myHost.content.findName("Border");
var text = myHost.content.findName("Text");
var perc = 0;
if (eventArgs.progress) {
perc = eventArgs.progress;
} else {
perc = eventArgs.get_progress();
}
bar.Width = perc * border.Width;
text.Text = parseInt(perc * 100) + "%";
}
</script>
<UserControl
x:Class="FullScreen.MainPage"
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"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
>
<UserControl.Resources>
<Style x:Key="LabelStyle" TargetType="TextBlock">
<Setter Property="Margin" Value="0,0,5,0"/>
</Style>
<Style x:Key="ValueStyle" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</UserControl.Resources>
<Border
Background="LightBlue"
BorderThickness="1"
BorderBrush="Black"
CornerRadius="5"
Margin="5"
>
<Grid
Margin="5"
>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button
x:Name="ToggleFullScreenButton"
Content="Toggle Full Screen"
Click="ToggleFullScreenButton_Click"
Margin="5"
/>
<TextBlock
Grid.Row="1"
Style="{StaticResource LabelStyle}"
Text="Host.Content.ActualWidth:"
/>
<TextBlock
x:Name="ContentActualWidthTextBlock"
Grid.Row="1" Grid.Column="1"
Style="{StaticResource ValueStyle}"
/>
<TextBlock
Grid.Row="2"
Style="{StaticResource LabelStyle}"
Text="Host.Content.ActualHeight:"
/>
<TextBlock
x:Name="ContentActualHeightTextBlock"
Grid.Row="2" Grid.Column="1"
Style="{StaticResource ValueStyle}"
/>
<TextBlock
Grid.Row="3"
Style="{StaticResource LabelStyle}"
Text="Host.Content.IsFullScreen:"
/>
<TextBlock
x:Name="ContentIsFullScreenTextBlock"
Grid.Row="3" Grid.Column="1"
Style="{StaticResource ValueStyle}"
/>
</Grid>
</Border>
</UserControl>
public partial class MainPage : UserControl
{
private readonly Content hostContent;
public MainPage()
{
InitializeComponent();
hostContent = Application.Current.Host.Content;
hostContent.Resized += HostContent_SizeChanged;
hostContent.FullScreenChanged += HostContent_SizeChanged;
DisplayInformation();
}
void HostContent_SizeChanged(object sender, System.EventArgs e)
{
DisplayInformation();
}
private void DisplayInformation()
{
ContentActualHeightTextBlock.Text = hostContent.ActualHeight.ToString();
ContentActualWidthTextBlock.Text = hostContent.ActualWidth.ToString();
ContentIsFullScreenTextBlock.Text = hostContent.IsFullScreen.ToString();
}
private void ToggleFullScreenButton_Click(object sender, RoutedEventArgs e)
{
hostContent.IsFullScreen = !hostContent.IsFullScreen;
}
}
hostContent = Application.Current.Host.Content;
// The following line has no effect:
hostContent.IsFullScreen = true;
<OutOfBrowserSettings ShortName="FS & OoB App" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
<OutOfBrowserSettings.Blurb>
This application demonstrates the full screen and out-of-browser features of Silverlight 3.
</OutOfBrowserSettings.Blurb>
<OutOfBrowserSettings.WindowSettings>
<WindowSettings Title="FullScreen & OutOfBrowser Application" Height="200" Width="200" />
</OutOfBrowserSettings.WindowSettings>
<OutOfBrowserSettings.Icons>
<Icon Size="16,16">images/16.png</Icon>
<Icon Size="32,32">images/32.png</Icon>
<Icon Size="48,48">images/48.png</Icon>
<Icon Size="128,128">images/128.png</Icon>
</OutOfBrowserSettings.Icons>
</OutOfBrowserSettings>
<Button
x:Name="OutOfBrowserButton"
Grid.Column="1"
Content="Out of Browser"
Click="OutOfBrowserButton_Click"
Margin="5"
Width="120"
HorizontalAlignment="Left"
/>
private void OutOfBrowserButton_Click(object sender, RoutedEventArgs e)
{
Application.Current.Install();
}
<OutOfBrowserSettings ShortName="FS OoB App" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
<OutOfBrowserSettings.Blurb>This application demonstrates the full screen and out-of-browser features of Silverlight 3.</OutOfBrowserSettings.Blurb>
<OutOfBrowserSettings.WindowSettings>
<WindowSettings Title="FullScreen & OutOfBrowser Application" Height="200" Width="200" />
</OutOfBrowserSettings.WindowSettings>
<OutOfBrowserSettings.Icons>
<Icon Size="16,16">images/16.png</Icon>
<Icon Size="32,32">images/32.png</Icon>
<Icon Size="48,48">images/48.png</Icon>
<Icon Size="128,128">images/128.png</Icon>
</OutOfBrowserSettings.Icons>
</OutOfBrowserSettings>
<TextBlock
Grid.Row="4"
Style="{StaticResource LabelStyle}"
Text="InstallState:"
/>
<TextBlock
x:Name="InstallStateTextBlock"
Grid.Row="4" Grid.Column="1"
Style="{StaticResource ValueStyle}"
/>
<TextBlock
Grid.Row="5"
Style="{StaticResource LabelStyle}"
Text="IsRunningOutOfBrowser:"
/>
<TextBlock
x:Name="IsRunningOutOfBrowserTextBlock"
Grid.Row="5" Grid.Column="1"
Style="{StaticResource ValueStyle}"
/>
private readonly Application app;
public MainPage()
{
InitializeComponent();
app = Application.Current;
hostContent = app.Host.Content;
// The following line has no effect:
hostContent.IsFullScreen = true;
hostContent.Resized += HostContent_SizeChanged;
hostContent.FullScreenChanged += HostContent_SizeChanged;
app.InstallStateChanged += HostContent_SizeChanged;
DisplayInformation();
}
private void DisplayInformation()
{
ContentActualHeightTextBlock.Text = hostContent.ActualHeight.ToString();
ContentActualWidthTextBlock.Text = hostContent.ActualWidth.ToString();
ContentIsFullScreenTextBlock.Text = hostContent.IsFullScreen.ToString();
InstallStateTextBlock.Text = app.InstallState.ToString();
IsRunningOutOfBrowserTextBlock.Text = app.IsRunningOutOfBrowser.ToString();
}
<Button
x:Name="CheckUpdateButton"
Grid.Row="6"
Content="Check Update"
Click="CheckUpdateButton_Click"
Margin="5"
/>
public MainPage()
{
InitializeComponent();
app = Application.Current;
hostContent = app.Host.Content;
// The following line has no effect:
hostContent.IsFullScreen = true;
hostContent.Resized += HostContent_SizeChanged;
hostContent.FullScreenChanged += HostContent_SizeChanged;
app.InstallStateChanged += HostContent_SizeChanged;
app.CheckAndDownloadUpdateCompleted += CheckAndDownloadUpdateCompleted;
DisplayInformation();
}
void CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
string info = "";
if (e.UpdateAvailable)
{
info = "A new version has been installed, restart the application.";
}
else if (e.Error == null)
{
info = "There is no new version";
}
else if (e.Error is PlatformNotSupportedException)
{
info = "There is a new version of the application, but it requires a new version of Silverlight";
}
else
{
info = string.Format("Error: {0}", e.Error.ToString());
}
MessageBox.Show(info);
}
private void CheckUpdateButton_Click(object sender, RoutedEventArgs e)
{
app.CheckAndDownloadUpdateAsync();
}
<TextBlock
Grid.Row="6" Grid.Column="1"
Text="This is an updated version!"
Foreground="Red"
FontWeight="Bold"
VerticalAlignment="Center"
/>