strana 378
----------
<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel Orientation="Vertical">
    <Image Source="/FullScreen;component/queen.jpg"></Image>
    <Button Content="Full screen" x:Name="btFS"   Margin="5" Width="120" 
      Click="btFS_Click" />
  </StackPanel>
</Grid>


C#:
private void btFS_Click(object sender, RoutedEventArgs e)
{
  Application.Current.Host.Content.IsFullScreen = true;  
}


strana 379
----------
C#:
void ScreenChanged(object sender, EventArgs e)
{
  if (Application.Current.Host.Content.IsFullScreen)
  {
    string message = String.Format("FULL SCREEN>> ActualWidth={0}, 
      ActualHeight={1}", 
    Application.Current.Host.Content.ActualHeight,
    Application.Current.Host.Content.ActualHeight);
    MessageBox.Show(message);   

  }
  else
  {
    string message = String.Format("ActualWidth={0}, ActualHeight={1}",
    Application.Current.Host.Content.ActualHeight,
    Application.Current.Host.Content.ActualHeight);
    MessageBox.Show(message);   
  }
}



strana 385
----------
C#:

if (App.Current.InstallState == InstallState.Installed && 
  App.Current.IsRunningOutOfBrowser)
{
  App.Current.CheckAndDownloadUpdateCompleted += (s, e) =>
  {
    if (e.UpdateAvailable)
      MessageBox.Show("Aplikace byla aktualizována na nejnovější verzi.\n
      Proto je nutné aplikaci restartovat");
  };
  App.Current.CheckAndDownloadUpdateAsync();
}



strana 386
----------
<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel Orientation="Vertical">
    <TextBlock Text="Adresář obrázků" FontSize="14" 
      FontWeight="Bold"></TextBlock>
    <TextBlock Text="Aplikaci je potřeba nainstalovat 
      na lokální počítač"></TextBlock>
    <ListBox Name="lb" ></ListBox> 
  </StackPanel>
</Grid>


C#:
using System.IO;
using System.Collections.ObjectModel;

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

      if (Application.Current.HasElevatedPermissions) 
      {
        string path = 
          Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); 
        var files=Directory.EnumerateFiles(path);
        ObservableCollection<string> picFiles = 
          new ObservableCollection<string>(files); 
          lb.ItemsSource = picFiles; 
      }
      else
        MessageBox.Show("Aplikace bude fungovat po instalaci 
        v režimu Out of browser!", " Režim rozšířeného přístupu ", 
        MessageBoxButton.OK);

    }
  }
}


strana 387
----------
private void btZapis_Click(object sender, RoutedEventArgs e)
{
  var sampleFile = @"\pokus.txt";
  var path = Environment.GetFolderPath(Environment.SpecialFolder. MyDocuments);
  if (System.IO.File.Exists(path + sampleFile))
  {
    System.IO.File.Delete(path + sampleFile);
  }
  StreamWriter sw = File.CreateText(path + sampleFile);
  sw.WriteLine("Text ukládaný do dokumentu...");
  sw.Close();
}



strana 388
----------
<Grid x:Name="LayoutRoot" Background="White">
  <TextBlock Text="Aplikaci je potřeba nainstalovat na lokální počítač" 
    FontSize="14"></TextBlock>
  <Button Name="btMail" Content="Pošli e-mail" Height="30"  Width="75" 
    Click="btMail_Click" />
</Grid>




C#:

using System.Windows.Interop;

private void btMail_Click(object sender, RoutedEventArgs e)
{
  if (Application.Current.HasElevatedPermissions && 
  AutomationFactory.IsAvailable) 
  {

    dynamic outlook = AutomationFactory.CreateObject("Outlook.Application"); 
    dynamic mail = outlook.CreateItem(0); 
    mail.To = "llacko@pcrevue.sk"; 
    mail.Subject = "Připomínka ke knize Silverlight "; 
    mail.Body = "Moje připomínka se týká ..."; 
    mail.Display();  
  }
  else
    MessageBox.Show("Tato funkce je dostupná jen v offline režimu!", 
    "Režim rozšířeného přístupu ", MessageBoxButton.OK);
}


strana 389
----------
<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel  Background="White" Orientation="Vertical">
    <my:DataGrid AutoGenerateColumns="True" ColumnWidth="*" 
      x:Name="dgMesta" ItemsSource="{Binding Path=Mesta}">
    </my:DataGrid>
    <Button Content="Export do Excelu" x:Name="btExport" 
      Margin="5" Width="120" Click="btExport_Click" />
  </StackPanel>
</Grid>


C#:
using System.ComponentModel;
using System.Windows.Interop;

namespace OOBdata
{
  public partial class MainPage : UserControl
  {
    public event PropertyChangedEventHandler PropertyChanged;

    private Lokality _mesta = new Lokality();

    public Lokality Mesta
    {
      get {return _mesta;}
      set
      {
        _mesta = value;
        if (null != PropertyChanged)
          PropertyChanged(this, new PropertyChangedEventArgs("Mesta"));
      }

    }


    public MainPage()
    {
      InitializeComponent();
      InicializaceDat(Mesta);
      this.DataContext = this;
    }

    private void InicializaceDat(Lokality _lokality)
    {
      _lokality.Add(new cPoloha("Brezno", 48.805172, 19.638518));
      _lokality.Add(new cPoloha("Ružomberok", 49.073327, 19.317253));
      _lokality.Add(new cPoloha("Handlová", 48.726635, 18.767438));
      _lokality.Add(new cPoloha("Žiar nad Hronom", 48.589838, 18.864314));
      _lokality.Add(new cPoloha("Detva", 48.564213, 19.421374));
      _lokality.Add(new cPoloha("Tisovec", 48.680959, 19.941835));
    }

    private void btExport_Click(object sender, RoutedEventArgs e)
    {
      if (App.Current.IsRunningOutOfBrowser && AutomationFactory.IsAvailable)
      {
        dynamic excel = 
          AutomationFactory.CreateObject("Excel.Application");

        excel.Workbooks.Add();
        excel.Cells[1, 1] = "Název";
        excel.Cells[1, 2] = "Zem. šířka";
        excel.Cells[1, 3] = "Zem. délka";

        int i = 2;
        // kopírování údajů do buněk
        foreach (cPoloha mesto in Mesta)
        {
          excel.Cells[i, 1] = mesto.sNazev;
          excel.Cells[i, 2] = mesto.dLatitude.ToString("F");
          excel.Cells[i, 3] = mesto.dLongitude.ToString("F");
          i++;
        }

        excel.Visible = true;
      }
      else
        MessageBox.Show("Tato funkce je dostupná jen v offline režimu!", 
          "a jen v režimu rozšířeného přístupu", MessageBoxButton.OK);

    }
  }

  public class cPoloha
  {
    public string sNazev { get; set; }
    public double dLatitude { get; set; }
    public double dLongitude { get; set; }

    public cPoloha(string nazev, double latitude, double longitude)
    {
      sNazev = nazev;
      dLatitude = latitude;
      dLongitude = longitude;
    }
  }

  public class Lokality : ObservableCollection<cPoloha>
  {
  }
}



strana 392
----------
<StackPanel x:Name="LayoutRoot" Background="White" Margin="20">

  <TextBlock x:Name="networkIndicator" FontWeight="Bold" FontSize="20"/>

  <Button x:Name="btInstall" Content="Instalace" 
    HorizontalAlignment="Left" Margin="0,10" Padding="10,5" 
    Click="btInstall_Click" />
  <Button x:Name="btUpdate" Content="Kontrola aktualizací" 
    HorizontalAlignment="Left" Margin="0,10" Padding="10,5" 
    Click="btUpdate_Click" />

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="Název = " FontWeight="Bold"/>
    <TextBlock Text="{Binding ShortName}"/>
  </StackPanel>

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="Popis = " FontWeight="Bold"/>
    <TextBlock Text="{Binding Blurb}"/>
  </StackPanel>

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="WindowSettings.Title = " FontWeight="Bold"/>
    <TextBlock Text="{Binding WindowSettings.Title}"/>
  </StackPanel>

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="WindowSettings.Height = " FontWeight="Bold"/>
    <TextBlock Text="{Binding WindowSettings.Height}"/>
  </StackPanel>

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="WindowSettings.Width = " FontWeight="Bold"/>
    <TextBlock Text="{Binding WindowSettings.Width}"/>
  </StackPanel>

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="IsRunningOutOfBrowser = " FontWeight="Bold"/>
    <TextBlock x:Name="isRunningOutOfBrowserTextBlock"/>
  </StackPanel>

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="InstallState = " FontWeight="Bold"/>
    <TextBlock x:Name="installStateTextBlock"/>
  </StackPanel>
</StackPanel>


C#:
using System.Net.NetworkInformation;

Application app = Application.Current;

public MainPage()
{
  InitializeComponent();
  LayoutRoot.DataContext = Deployment.Current.OutOfBrowserSettings;
  UpdateUI();
  app.CheckAndDownloadUpdateCompleted +=
    App_CheckAndDownloadUpdateCompleted;
  app.InstallStateChanged += (s, e) => UpdateUI();
  NetworkChange.NetworkAddressChanged +=
    (s, e) => UpdateNetworkIndicator();

}

private void UpdateUI()
{
  UpdateNetworkIndicator();

  btInstall.Visibility =
    app.InstallState == InstallState.NotInstalled ?
    Visibility.Visible : Visibility.Collapsed;

  btUpdate.Visibility =
    app.IsRunningOutOfBrowser ? 
    Visibility.Visible : Visibility.Collapsed;

  isRunningOutOfBrowserTextBlock.Text = 
    app.IsRunningOutOfBrowser.ToString();

  installStateTextBlock.Text = app.InstallState.ToString();
}

private void UpdateNetworkIndicator()
{
  networkIndicator.Visibility =
    app.IsRunningOutOfBrowser ?
    Visibility.Visible : Visibility.Collapsed;

  bool online = NetworkInterface.GetIsNetworkAvailable();
  networkIndicator.Text = online ? "ONLINE" : "OFFLINE";
  btUpdate.Visibility = online ? Visibility.Visible : Visibility.Collapsed;
}

private void btInstall_Click(object sender, RoutedEventArgs e)
{
  try
  {
    app.Install();
  }
  catch (InvalidOperationException)
  {
    MessageBox.Show("Aplikace je už nainstalována. ");
  }
}

private void btUpdate_Click(object sender, RoutedEventArgs e)
{
  app.CheckAndDownloadUpdateAsync();
}

private void App_CheckAndDownloadUpdateCompleted(object sender, 
  CheckAndDownloadUpdateCompletedEventArgs e)
{
  if (e.UpdateAvailable)
  {
    MessageBox.Show("Byla stažena aktualizace, restartujte aplikaci ");
  }
  else if (e.Error != null && e.Error is PlatformNotSupportedException)
  {
    MessageBox.Show("Byla stažena aktualizace, vyžadující 
      novější verzi platformy Silverlight");
  }
  else
  {
    MessageBox.Show("Aktualizace není k dispozici.");
  }
}


strana 395
----------
<Grid x:Name="LayoutRoot" Background="White">
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="30"/>
  </Grid.RowDefinitions>

  <Image Source="/FullScreen;component/queen.jpg" Grid.Row="0"></Image>
  <Button Content="Oznam" x:Name="btOznam" Width="120" Grid.Row="1" 
    Click="btOznam_Click" />
</Grid>


C#:
private void btOznam_Click(object sender, RoutedEventArgs e)
{
  NotificationWindow notify = new NotificationWindow();
  notify.Width = 300;
  notify.Height = 80;
  TextBlock tb = new TextBlock();
  tb.Text = "Aktuální oznámení";
  notify.Content = tb;
  notify.Show(3000);





strana 396
----------
<Grid x:Name="LayoutRoot" Background="White">
  <Grid.RowDefinitions>
    <RowDefinition Height="40"/>
    <RowDefinition Height="*"/>
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="520*" />
    <ColumnDefinition Width="80" />
  </Grid.ColumnDefinitions>
  <TextBox x:Name="tbNavigator" Height="30" Grid.Row="0" Grid.Column="0" />
  <Button Content="GO" x:Name="btUrl"  Width="75" Height="30" Grid.Row="0" 
    Grid.Column="1" Click="btUrl_Click" />
  <WebBrowser x:Name="wbWeb"  Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" />
</Grid>


test.html:

<html>
  <head>
    <title>Testovací stránka</title>
  </head>
  <body>
    <div style="float:left;width:200px;height:100px;
      background:yellow;color:Brown">
      Text v rámečku...</div>
  </body>
</html>


strana 399
----------


<Grid x:Name="LayoutRoot">
   <Grid.RowDefinitions>
      <RowDefinition Height="30"/>
      <RowDefinition Height="0.5*"/>
      <RowDefinition Height="0.5*"/>
   </Grid.RowDefinitions>
   <Grid.Background>
      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="Black" Offset="0"/>
        <GradientStop Color="White" Offset="1"/>
      </LinearGradientBrush>
   </Grid.Background>

<WebBrowser x:Name="wb" Margin="0,3,0,0" 
    Source="http://localhost:port/stranka.htm" Grid.Row="1" Grid.RowSpan="1"/>
    <Button Content="Navigate" 
       HorizontalAlignment="Left" Height="23" VerticalAlignment="Bottom" 
       Width="80" Click="Button_Click" />

<Rectangle x:Name="Rectangle1" Grid.Row="2" Stroke="Black">
   <Rectangle.Fill>
      <WebBrowserBrush x:Name="htmlBrush" SourceName="wb" />
   </Rectangle.Fill>
  </Rectangle>
</Grid>



strana 400
----------
C#:
using System.Xml;
using System.ServiceModel.Syndication;
using System.Text;

private void btUrl_Click(object sender, RoutedEventArgs e)
{
  WebClient proxy = new WebClient();
  proxy.OpenReadCompleted += new 
    OpenReadCompletedEventHandler(proxy_OpenReadCompleted);
  proxy.OpenReadAsync(new Uri(tbNavigator.Text));
}

void proxy_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
  if (e.Error == null)
  {
    XmlReader rdr = XmlReader.Create(e.Result);
    SyndicationFeed sf = SyndicationFeed.Load(rdr);
    StringBuilder sb = new StringBuilder();

    foreach (var item in sf.Items)
    {
      sb.Append(item.Title.Text);
      sb.Append("<br/>");
      sb.Append(item.Summary.Text);
      sb.Append("<hr/>");
    }
    tbNavigator.Text = sb.ToString();
    wbWeb.NavigateToString(sb.ToString());
  }
}



