niedziela, 11 grudnia 2011

Notatki o Windows 8 - odc. 11

Zagadnienia z kilku ostatnich wpisów w wersji XAML/C#. Uwagę zwracają pewne różnice w stosunku do innych platform XAML (WPF, Silverlight, Silverlight for Windows Phone), niektóre kontrolki niewymienione przy JS lub występujące pod inną nazwą oraz zdarzenia manipulacji.

Silverlight differences:

  • app model
  • controls
  • no mouse/keyboard events
  • some API were cut to boost performance (f.e OpacityMask, Rectangular clips, Corner radius, Custom easing functions, and Effects)
  • animations - added some additional theme and transition animations, not all animations are enabled by default
  • DRM differences
  • WinRT vs BCL support (f.e WinRT IInspectables don't have .Equals, .Hashcode, .ToString, operator overloads etc. unlike System.Object; Also WinRT does not support struct member functions so we've created some *Helper types)
  • Graphics - VideoBrush is not supported. RadialGradientBrush is not supported. Applying an ImageBrush to the Foreground of a TextBlock is not supported. Non-rectangular clipping is not supported.

Bubbling events – f.e PointerPressed

MyTB.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Xaml.Media.Colors.Red);


New controls:

  • ApplicationBar
  • CarouselPanel
  • CaptureElement
  • FlipView
  • GridView
  • JumpViewer
  • ListView
  • MediaPlayer
  • PopupMenu
  • ProgressRing
  • RichTextBlock
  • ToggleSwitch
  • VariableSizedWrapGrid
  • WebView i WebViewBrush
  • WrapGrid

<FlipView Width="350" Height="150">

    <FlipViewItem>

        <Image Width="100" Height="100" Source="Images/Logo.png"/>

    </FlipViewItem>

    <FlipViewItem>

        <Image Width="100" Height="100" Source="Images/SplashScreen.png"/>

    </FlipViewItem>

</FlipView>

      <GridView/>

      <JumpViewer/>

MediaPlayer - allows selection and simple editing (cut/copy/paste, etc.) of audio content.

       <ProgressRing IsActive="True"/>

       <RichTextBlock/>

Zooming scroll viewer - displays a view of content a user can zoom in/out of, and various features like snap points, etc. that enhance that experience.

<ScrollViewer ZoomMode="Enabled"

                MinZoomFactor="1.0" MaxZoomFactor="10.0"

                Width="500" Height="500"

                HorizontalScrollBarVisibility="Auto"

                HorizontalScrollMode="Enabled"

                BorderBrush="White" BorderThickness="1"

                Name="zoomer">

    <Image Source="Images/Logo.png" Width="500" Height="500" />

       </ScrollViewer>

Apps can display content on the lock screen if they declare themselves capable in their manifest. This content simply mirrors the content of the app's tile or badge and does not require any additional API calls.

Creating a tile

TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

tileUpdater.Clear();

TileTemplateType templateType = TileTemplateType.TileWideSmallImageAndText01;

XmlDocument tileXml  = TileUpdateManager.GetTemplateContent(templateType);

XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");

 

int index = 1;

 

foreach (XmlNode tileTextAttr in tileTextAttributes)

{

    tileTextAttr.InnerText = "textField " + Convert.ToString(index);

    index++;

}

 

XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");

 

((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-resource:images/redWide.png");

((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");

TileNotification tileNotification = new TileNotification(tileXml);

tileUpdater.EnableNotificationQueue(true);

tileNotification.Tag = "tag01";

int seconds = 10;                       

 

DateTimeOffset currentTime = DateTimeOffset.Now;

currentTime.AddSeconds(seconds);

 

tileNotification.ExpirationTime = currentTime;

Touch

To use the built-in touch support, you can handle pointer events to detect simple, one-finger interactions such as tap. Pointer event handlers can be quickly added to your app and are an easy way to get basic touch support.

To use more elaborate interactions, handle the manipulation events, such as ManipulationStarted, ManipulationDelta and ManipulationCompleted. These provide access to multi-touch interactions and interactions that use inertia and velocity data.

The Windows Runtime pointer events such as PointerReleased and PointerMoved can be used to support simple, one-finger interactions such as tapping. For multi-touch interactions such as pinching, and interactions that use inertia and velocity data such as dragging, you use the manipulation events.

The simplest way to enable touch input in your app is by using pointer events. Pointer events automatically support touch, mouse, and keyboard input, so you should use them instead of more traditional events such as Click.

Pointer events are limited to single-finger interactions such as tap, and they don't support velocity-based interactions. Single finger touches on the screen are converted to an equivalent Windows Runtime pointer event such as PointerPressed when you place your finger on the screen, PointerReleased when you lift your finger, and PointerMoved when you drag your finger across the screen. Other pointer events that are used by a Metro style app using C++, C#, or Visual Basic are PointerExited and PointerEntered. The event arguments for the pointer events are PointerEventArgs.

You can use manipulation events to detect interactions such as drag, pinch, and hold.

A interaction event in a Metro style app using C++, C#, or Visual Basic consists of a series of manipulation events. Each interaction starts with a ManipulationStarted event, such as when a user touches the screen. Next, one or more ManipulationDelta events are fired. Finally, a ManipulationCompleted event is raised when the interaction is finished.

<Rectangle Name="TestRectangle" Width="200" Height="200" Fill="Blue" />

private TranslateTransform dragTranslation;

 

// Constructor

public MainPage()

{

    InitializeComponent();

 

    // Add handler for the ManipulationDelta event

    TestRectangle.ManipulationDelta +=

        new EventHandler<ManipulationDeltaEventArgs>(Drag_ManipulationDelta);

    dragTranslation = new TranslateTransform();

    TestRectangle.RenderTransform = this.dragTranslation;

}

 

void Drag_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)

{

    // Move the rectangle.

    dragTranslation.X += e.DeltaManipulation.Translation.X;

    dragTranslation.Y += e.DeltaManipulation.Translation.Y;

}

Note  Windows Developer Preview does not support change notification in the ObservableCollection<T> class because it does not currently implement the IObservableVector interface. However, you can work around this issue using the sample ObservableVector<T> class available in the data binding sample.

sample with StringFormatConverter

Asynchronous methods in the Windows runtime return the following types:

App lifecycle

public MainPage(String launchingString, Boolean restoreState)

{

       InitializeComponent();

       App.Current.Activated +=new ActivatedEventHandler(App_Activated);

       App.Current.Suspending +=new SuspendingEventHandler(App_Suspending);

}


private void App_Resuming(object sender, object e)

{

    if (e.Kind == Windows.ApplicationModel.Activation.ActivationKind.Launch) {

         

        if (e.PreviousExecutionState == Windows.ApplicationModel.Activation.ApplicationExecutionState.Terminated)

        {

            // TODO: Populate the UI with the previously saved application data            

        }

        else

        {

            // TODO: Populate the UI with defaults            

        }

    }

} 


CoreDispatcher dispatcher = Window.Current.Dispatcher;


private void App_Suspending(object sender, object e)

{

      // If your application needs time to complete a lengthy operation, it can request a deferral.

      // The SuspendingOperation has a deadline time. Make sure all your operations are complete by that time!

      // If the app doesn't return from this handler within five seconds, it will be terminated.

      SuspendingOperation op = (e as SuspendingEventArgs).SuspendingOperation;

      SuspendingDeferral deferral = op.GetDeferral(); 

                

      IPropertySet settingsValues = ApplicationData.Current.LocalSettings.Values;

      if (settingsValues.ContainsKey("Scenario"))

      {

          settingsValues.Remove("Scenario");

      }

      settingsValues.Add("Scenario", ScenarioList.SelectedIndex);

 

      dispatcher.Invoke(CoreDispatcherPriority.Normal, (object invokedSender, InvokedHandlerArgs invokedArgs) =>

      {

          Scenario2OutputText.Text = "A suspending operation was received at " + DateTime.Now.ToString();

      }, this, null);

     

      deferral.Complete();

}

When the user switches to your terminated app, the system sends the Resuming event.

c.d.n

Brak komentarzy: