Reaali Robootika.COM

NXT robotimaailm ja programmeerimine C-keeles

Windows Phone – CompositeTransform

Käesolev programminäide iseloomustab seda, kuidas lihtsal moel panna pildid liikuma CompositeTransform funktsiooni abil. Nihutades ekraanil olevaid slaidereid, liigub pilt kas üles-alla, pöörab kohapeal või venitatakse seda x-telje suunas laiemaks-kitsamaks.

CompositeTransform võimaldab järgmisi funktsioone rakendada:

·         Objekti liigutamine x või y telje suunal – TranslateX, TranslateY

·         Objekti suuruse muutmine x või y suunal – scaleX, scaleY

·         Objekti pööramine – Rotation

·         Objekti kuju muutmine – SkewX, SkewY

CompositeTransform kohta leiab siit MSDN artiklist lugemist: http://msdn.microsoft.com/en-us/library/system.windows.media.compositetransform(v=vs.95).aspx 

Vaata videost mida alltoodud rakendus teeb.

Windows Phone Composite Transform

MainPage.xaml

<phone:PhoneApplicationPage
   x:Class="Phone_Liikuvad_pildid.MainPage"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
   xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
   FontFamily="{StaticResource PhoneFontFamilyNormal}"
   FontSize="{StaticResource PhoneFontSizeNormal}"
   Foreground="{StaticResource PhoneForegroundBrush}"
   SupportedOrientations="Portrait" Orientation="Portrait"
   shell:SystemTray.IsVisible="True">

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Slider Height="84" HorizontalAlignment="Left" Margin="12,6,0,0" Name="slider1" VerticalAlignment="Top" Width="438" ValueChanged="slider1_ValueChanged" Minimum="0" Maximum="3" SmallChange="0.5" />
            <Slider Height="84" HorizontalAlignment="Left" Margin="12,96,0,0" Name="slider2" VerticalAlignment="Top" Width="438" ValueChanged="slider2_ValueChanged" Maximum="720" />
            <Slider Height="594" HorizontalAlignment="Left" Margin="12,124,0,0" Name="slider3" VerticalAlignment="Top" Width="67" ValueChanged="slider3_ValueChanged" Orientation="Vertical" Maximum="400" />
            <Image HorizontalAlignment="Left" Margin="125,556,0,0" Name="MSlogoPilt" Stretch="Fill" VerticalAlignment="Top" Source="/Phone%20Liikuvad%20pildid;component/MSLogo.jpg" RenderTransformOrigin="0.5,0.5" Height="162" Width="236" />
        </Grid>
    </Grid
>

</
phone:PhoneApplicationPage
>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Phone_Liikuvad_pildid
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            //antakse slideritele algväärtused
            slider1.Value = 1;
            slider3.Value = 200;
        }
        private void MoveImage() {
            //loetakse slideritest info
            double scaleX = slider1.Value;
            double Rotation = slider2.Value;
            double TranslateY = slider3.Value;

            //luuakse CompositeTransform objekt
            CompositeTransform ct = new CompositeTransform();

            //antakse loodud objektile edasi omadused
            ct.ScaleX = scaleX;
            ct.TranslateY = -TranslateY;
            ct.Rotation = Rotation;

            //rakendatakse omadused pildi peal
            MSlogoPilt.RenderTransform = ct;
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            MoveImage();
        }

        private void slider2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            MoveImage();
        }

        private void slider3_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            MoveImage();
        }
    }
}

Add comment

Loading