Hands-On Lab. Sensors -.NET. Lab version: Last updated: 12/3/2010

Size: px
Start display at page:

Download "Hands-On Lab. Sensors -.NET. Lab version: Last updated: 12/3/2010"

Transcription

1 Hands-On Lab Sensors -.NET Lab version: Last updated: 12/3/2010

2 CONTENTS OVERVIEW... 3 EXERCISE 1: INTEGRATING THE SENSOR API INTO A WPF APPLICATION... 5 Task 1 Prepare a WPF Project for Sensor Integration... 5 Task 2 Add Layout to the WPF Application... 7 Task 3 Add Image Specific Logic Task 4 Setting up the Sensor Helper Task 5 Integrating ViewModel and the Sensor Helper Task 6 Add Light Sensor Interaction with the UI Task 7 Add Accelerometer Sensor Interaction with the UI (Optional) SUMMARY

3 Overview The Windows 7 Sensor & Location Platform enables your applications to adapt to the current environment and change the way they look, feel or behave. Here are few examples: When using a mobile PC (for example, a laptop or tablet) outdoors in a sunny day, an application might increase brightness, contrast and de-saturate colors to increase screen readability An application might provide location-specific information, such as nearby restaurants An application might use 3D accelerometer and buttons as a game controller An application might use a human presence sensor to change the state of the Messenger status Figure 1 Modified MSDN Reader that uses an ambient light sensor to change contrast, size and color saturation The Sensor & Location Platform has many advantages compared to proprietary solutions: Hardware-independence: No need to learn and invest in a particular vendor's API; all sensors types are handled very similarly Privacy: Because Microsoft recognizes that sensor and location data are private, personally identifying information, all sensors are disabled by default. You can enable/disable sensors at any time via the Control Panel. Applications might prompt you to enable specific sensors via a secure consent UI. 3

4 Application sharing: Multiple applications can consume data from the same sensor simultaneously Location simplicity: The Location API lets you obtain the location without caring about the particular mechanism used to obtain the information, for example, GPS, cell-tower or Wi-Fi hotspot triangulation. The Location API automatically chooses the most accurate sensor data available. In addition, you don't need to implement GPS protocols such as NMEA. Objectives In this Hands-On Lab, you will learn how to integrate the Sensor API into your WPF application. Like the Location API, the Sensor API is COM-based. You will use the Windows API Code Pack that wraps the Sensor API in a type-safe and convenient way. System Requirements You must have the following items to complete this lab: Microsoft Visual Studio 2008 SP1 Windows 7 RC or later Graphics card fully supporting DirectX and PixelShaders. Hardware with Windows 7-compatible Ambient Light Sensor with driver installed or Virtual Ambient Light Sensor Hardware with Windows 7-compatible 3-axis Accelerometer with driver installed (optional) 4

5 Exercise 1: Integrating the Sensor API into a WPF Application Task 1 Prepare a WPF Project for Sensor Integration 1. Start Visual Studio 2008 and open the Starter solution that contains one WPF application. The solution is located in your Starter folder. Figure 2 Starter solution The WPF project, SensorHOL, is already bundled with the premade Grayscale PixelShader effect that we will use later in this Lab, and a resource dictionary that includes several resources used by future WPF controls. 2. Add a new class named SensorViewModel to the project. MainWindow view will be data-binded to its properties. By using this pattern, the View is relieved from triggering its own updates and instead passively waits for the ViewModel to change. 5

6 Figure 3 Create SensorViewModel class 3. Implement the INotifyPropertyChanged interface in the SensorViewModel class. class SensorViewModel : INotifyPropertyChanged #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; #endregion 4. Add the following code (we call this method whenever we wish to raise the notification): #region INotifyPropertyChanged Members private void NotifyChange(string propertyname) if (PropertyChanged!= null) 6

7 PropertyChanged(this, newpropertychangedeventargs(propertyname)); 5. In order to connect this ViewModel with the View, add the line just after the InitializeComponent(), MainWindow.xaml.cs. public MainWindow() InitializeComponent(); DataContext = new SensorViewModel(); Test your code to make sure it compiled. Task 2 Add Layout to the WPF Application Figure 4 Sensor HOL basic Layout 7

8 In this task, you will design the MainWindow layout. It will contain 3 parts: Top part: Browse button and the photo name Left part: Several Sensor indicators Right part: An image. A slider divides the photo; sensor data in each portion of the image will display differently depending on the current light intensity. 1. Open the MainWindow.xaml file. Grid is a powerful layout mechanism provided by WPF. It will be our sole means for designing the layouts in this lab. 2. Start by adding rows and columns definitions. <Grid> <Grid.RowDefinitions> <RowDefinition Height="65"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="150"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> </Grid> 3. Next, add the right part of the Grid, just after the columns definitions. This Grid will contain the image and slider. <Grid Grid.Column="1" Grid.Row="1" x:name="overlaycontent" HorizontalAlignment="Center" VerticalAlignment="Center"> </Grid> 4. Add two image controls inside the OverlayContent Grid. Each will render a different effect and they are overlaid <Image Stretch="Uniform" Margin="10"> </Image> <Image Stretch="Uniform" Margin="10"> </Image> 8

9 5. Next, add the Slider control inside the Grid. Note that the slider width and height are data bound to the grid layout. <Slider x:name="overlayadjustmentslider" Width="Binding ElementName=OverlayContent, Path=ActualWidth" Height="Binding ElementName=OverlayContent, Path=ActualHeight" FocusVisualStyle="x:Null" Maximum="1" Minimum="0" Value="0.5" Template="DynamicResource Slider_ControlTemplate"> </Slider> 6. Let s focus on the left part of the layout: add another Grid, just after OverlayContent Grid. <Grid Width="150" Height="240" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top"> </Grid> Inside that Grid, you will add a sensor indicator control and the rest of the Sensor indicators. The inner Grid holds the Sensor Data caption. 7. Create a border with a caption. <Border Background="DynamicResource Brush_PopupBackground"> <Border.Effect> <DropShadowEffect BlurRadius="12" Direction="-90" ShadowDepth="3"/> </Border.Effect> </Border> <Border Background="DynamicResource Brush_PopupBackground" BorderBrush="StaticResource Brush_PopupBorder" BorderThickness="0,1,0,1" CornerRadius="3"> <Grid TextElement.FontFamily="Segoe UI" TextElement.FontSize="10"> <TextBlock HorizontalAlignment="Center" Margin="0,10" VerticalAlignment="Top" FontFamily="Segoe UI" FontSize="13" Foreground="White" Text="Sensor Data"/> </Grid> </Border> 8. The last part consists solely of a Grid containing a button and a caption. <Grid Grid.ColumnSpan="2" HorizontalAlignment="Stretch"> 9

10 <Button HorizontalAlignment="Left" Width="70" Margin="5" Height="40" Content="Browse..." Click="Button_Click"/> <TextBlock Foreground="White" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe UI"/> </Grid> 9. Now, add the code to handle the Browse Button click event to MainWindow view. private void Button_Click(object sender, RoutedEventArgs e) Your MainWindow should look like this: <Window x:class="sensorhol.mainwindow" xmlns=" xmlns:x=" Title="MainWindow" WindowState="Maximized" Background="Black"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="65"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="150"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid Grid.Column="1" Grid.Row="1" x:name="overlaycontent" HorizontalAlignment="Center" VerticalAlignment="Center"> <Image Stretch="Uniform" Margin="10"> </Image> <Image Stretch="Uniform" Margin="10"> </Image> <Slider x:name="overlayadjustmentslider" Width="Binding ElementName=OverlayContent, Path=ActualWidth" Height="Binding ElementName=OverlayContent, Path=ActualHeight" FocusVisualStyle="x:Null" Maximum="1" Minimum="0" Value="0.5" Template="DynamicResource Slider_ControlTemplate"> </Slider> </Grid> <Grid Width="150" Height="240" Grid.Row="1" 10

11 HorizontalAlignment="Left" VerticalAlignment="Top"> <Border Background="DynamicResource Brush_PopupBackground"> Direction="-90" <Border.Effect> <DropShadowEffect BlurRadius="12" ShadowDepth="3"/> </Border.Effect> </Border> <Border Background="DynamicResource Brush_PopupBackground" BorderBrush="StaticResource Brush_PopupBorder" BorderThickness="0,1,0,1" CornerRadius="3"> <Grid TextElement.FontFamily="Segoe UI" TextElement.FontSize="10"> <TextBlock HorizontalAlignment="Center" Margin="0,10" VerticalAlignment="Top" FontFamily="Segoe UI" FontSize="13" Foreground="White" Text="Sensor Data"/> </Grid> </Border> </Grid> <Grid Grid.ColumnSpan="2" HorizontalAlignment="Stretch"> <Button HorizontalAlignment="Left" Width="70" Margin="5" Height="40" Content="Browse..." Click="Button_Click"/> <TextBlock Foreground="White" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe UI" /> </Grid> </Grid> </Window> 10. Test your code to make sure it compiles. 11

12 Task 3 Add Image Specific Logic In the previous task, you designed the layout of the application, now it is time to pour content into it. 1. Open SensorViewModel. After you add a new property, the user will be able to browse to a file and this property will contain his image selection.. 2. Add the NotifyChange method. Each time this property is changed, the View will respond to this change. private string _imagepath; public string ImagePath get return _imagepath; set _imagepath = value; NotifyChange("ImagePath"); 3. Add the System.IO namespace to SensorViewModel. using System.IO; 4. Add a read-only property that requests the file name from the ImagePath property. public string ImageName get return Path.GetFileNameWithoutExtension(ImagePath); Now, we need to make sure that when ImagePath has changed, the UI binded to ImageName changes as well. 5. Add a call to NotifyChange, this time for the ImageName property. private string _imagepath; public string ImagePath 12

13 get return _imagepath; set _imagepath = value; NotifyChange("ImagePath"); NotifyChange("ImageName"); 6. Now let s implement: Go back to the view and register the necessary binding. <Image Source="Binding ImagePath" Stretch="Uniform" Margin="10">> </Image> <Image Source="Binding ImagePath" Stretch="Uniform" Margin="10">> </Image> 7. You can now data-bind the file name label. (Note: the binding is one-way because the property is read-only) <TextBlock Foreground="White" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe UI" Text="Binding ImageName, Mode=OneWay"/> The last piece of this puzzle is to set the ViewModel with a path to an image. To do this, you must go to the code-behind and implement the Button_Click method. This code will open the standard Windows Open File dialog. If the user decides to select an image, it is just a matter of setting the ViewModel with his selection. 8. First, add a namespace for the OpenFIleDialog. using Microsoft.Win32; 9. Now, you can implement Button_Click. OpenFileDialog openfiledialog = new OpenFileDialog(); openfiledialog.checkfileexists = true; openfiledialog.checkpathexists = true; openfiledialog.filter = "Image Files *.jpg *.png"; openfiledialog.multiselect = false; openfiledialog.showreadonly = true; 13

14 openfiledialog.validatenames = true; openfiledialog.restoredirectory = true; openfiledialog.title = "Find an Image"; bool? result = openfiledialog.showdialog(); if ((result.hasvalue) && (result.value)) (DataContext as SensorViewModel).ImagePath = openfiledialog.filename; 10. Compile and test your code: a. Browse for an image; you should see it on the right side of the screen. b. Browse for more images and note that the UI changes correspondingly. Task 4 Setting up the Sensor Helper 1. Expand References under the SensorHOL project. 2. Right-click on References and click Add Reference. 3. Click on the Browse tab and navigate to the folder where Microsoft.WindowsAPICodePack.Sensors.dll is located. 4. Select the DLL and click OK. 5. Create a new class named SensorHelper in a new file: SensorHelper.cs. 6. Define the class like this: The class' SensorType type parameter is the Sensor-derived sensor class (for example, AmbientLightSensor or Accelerometer3D). using System; using System.Collections.Generic; using Microsoft.WindowsAPICodePack.Sensors; using System.ComponentModel; public class SensorHelper<SensorType, SensorPropertyType> : INotifyPropertyChanged where SensorType : Sensor where SensorPropertyType : class 14

15 7. Paste the following code into the class: private SensorPropertyType _value; private SensorType _sensor; private Guid _sensorguid; public SensorHelper() public void Initialize() SensorList<SensorType> list = SensorManager.GetSensorsByTypeId<SensorType>(); if (list!= null) var permreqsensorlist = new SensorList<Sensor>(); foreach (var sensor in list) permreqsensorlist.add(sensor); SensorManager.RequestPermission(IntPtr.Zero, true, permreqsensorlist); foreach (var sensor in list) if (HandleNewSensor(sensor) && _sensor!= null) break; // subscribe to sensor added/removed event SensorManager.SensorsChanged += new SensorsChangedHandler(OnSensorsChanged); Initialize() requests a list of sensors from the Sensor Manager which are of type SensorType. When SensorHelper is used, SensorType would be either AmbientLightSensor or Acceleroemter3DSensor. Since the user account might not have permissions to use the sensors, we'll call SensorManager.RequestPermissions(), specifying the parent window handle, whether the 15

16 function is synchronous (modal), and the list of sensors for which we request access. This will pop up a dialog like this: Behind-the-scenes, the CodePack API wrapper maps each Sensor-derived type to a sensor type GUID that the COM API expects. The mapping information is provided by an attribute on the class: [SensorDescription("97F115C8-599A D2D A")] public class AmbientLightSensor : Sensor Initialize() then iterates over each found sensor and calls HandleNewSensor(). Finally, it subscribes to the SensorsChanged event that fires when new sensors are attached or existing sensors are removed. 8. Paste the following code into the SensorHelper class: private void OnSensorsChanged(SensorsChangedEventArgs change) // if sensor was added 16

17 if (change.change == SensorAvailabilityChange.Addition) // we use the base Sensor class as the type parameter // because we're not sure what sensor type was attached Sensor sensor = SensorManager.GetSensorBySensorId<Sensor>(change.SensorId); // if this is the right sensro type if (sensor is SensorType) HandleNewSensor(sensor); if (change.change == SensorAvailabilityChange.Removal && _sensorguid.equals(change.sensorid)) _sensor = null; _sensorguid = Guid.Empty; private bool HandleNewSensor(Sensor sensor) // Sensor may become Ready in the future, register for // StateChanged event sensor.statechanged += OnSensorStateChanged; if (sensor.state == SensorState.Ready) // If sensor is already in state Ready, use it PrepareSensor(sensor); return true; return false; The OnSensorsChanged method is the event handler for the SensorsChanged event we subscribed to in Initialize(). If a new sensor is attached, we obtain a base-class Sensor object from its instance GUID property (SensorId) which we get from the event arguments. Sensors have three GUIDs: Instance: Identifies the sensor instance uniquely Category: For example, environment, mechanical, electrical Type: For example, temperature, humidity, voltage, current, 3D accelerometer We then check if the sensor object is of the proper type. If so, we call HandleNewSensor(). 17

18 This approach allows the application to use sensors that are attached later. OnSensorsChanged() also handles sensor removal. It clears a variable that indicates what sensor is in use. This allows another sensor to be used if it becomes available. Sensors have many other properties such as Manufacturer, Model, SerialNumber, etc. These are standard properties. Various sensors might provide additional properties. HandleNewSensor() checks for the sensor's state. Even if a sensor is attached, it may not be ready to use. State tells you if the sensor is ready or the reason it's not. The hardware might be initializing, or a fault condition might exist, or the user might not have permission to use the sensor. If the sensor is ready to be used, we call PrepareSensor(). We call subscribe to the sensor's StateChanged event, which fires when the state changes. We could later use it if it becomes ready and we don't already have a sensor. 9. Paste the following code into the SensorHelper class: private void OnSensorStateChanged(Sensor sender, EventArgs e) if (sender.state == SensorState.Ready) PrepareSensor(sender); else if (!_sensorguid.equals(guid.empty) && _sensor.sensorid.equals(_sensorguid)) _sensor = null; _sensorguid = Guid.Empty; sender.datareportchanged -= OnDataUpdated; private void PrepareSensor(Sensor sensor) if (_sensor == null) _sensorguid = sensor.sensorid.value; _sensor = (SensorType)sensor; sensor.tryupdatedata(); sensor.datareportchanged += OnDataUpdated; OnSensorStateChanged() fires when a sensor state changes. If it's ready, we call PrepareSensor(). If it changes state to something other than Ready, we check if it's the one 18

19 sensor we're using. If so, we unsubscribe and clear the variable indicating that a sensor is in use. PrepareSensor() sets a variable indicating that a sensor is in use, so that another sensor of the same type won't take over if it is attached or becomes ready in the future. The function then subscribes to the DataReportChanged event. TryUpdateData() is called to force the sensor to generate a new data report. Some sensors might generate data reports periodically, while others will generate a data report once the measured value changes significantly enough. By calling TryUpdateData(), we initialize the UI with an initial value immediately. 10. Paste the following code into the SensorHelper class: private void OnDataUpdated(Sensor sender, EventArgs e) if (sender is AmbientLightSensor) _value = ((AmbientLightSensor)sender).CurrentLuminousIntensity as SensorPropertyType; else if (sender is Accelerometer3D) _value = ((Accelerometer3D)sender).CurrentAcceleration as SensorPropertyType; if (_value!= null) OnPropertyChanged("Value"); The OnDataUpdated() method handles the DataUpdated event. This event fires when the sensor has a new data report available. The data is accessed by getting one or more properties (which are different for each sensor). To access a property, the sensor needs to be cast to the appropriate derived type. 11. Paste the following code into the SensorHelper class: This code supports the integration of SensorHelper with the UI code. public SensorPropertyType Value get return _value; 19

20 #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) PropertyChangedEventHandler ph = this.propertychanged; if (ph!= null) ph(this, new PropertyChangedEventArgs(name)); #endregion Task 5 Integrating ViewModel and the Sensor Helper 1. Open SensorViewModel.cs and create a property with a private field that will expose a Light Sensor. private SensorHelper<AmbientLightSensor, AmbientLightSensor.LuminousIntensity> _sensor; public SensorHelper<AmbientLightSensor, AmbientLightSensor.LuminousIntensity> LightSensor get return _sensor; 2. Now we will do the same, but for the Accelerometer Sensor. private SensorHelper<Accelerometer3D, Accelerometer3D.Acceleration3D> _acceleromatersensor; public SensorHelper<Accelerometer3D, Accelerometer3D.Acceleration3D> AcceleromaterSensor get return _acceleromatersensor; 3. Add a constructor for SensorViewModel, in which we will set up the sensors 20

21 public SensorViewModel() _sensor = new SensorHelper<AmbientLightSensor, AmbientLightSensor.LuminousIntensity>(); _sensor.initialize(); _acceleromatersensor = new SensorHelper<Accelerometer3D, Accelerometer3D.Acceleration3D>(); _acceleromatersensor.initialize(); 4. Compile and test your code. You should be able to run and integrate with the sensors. Task 6 Add Light Sensor Interaction with the UI In the next task, we will make use of the light intensity sensor. Three separate elements will interact with it: LUM indicator: A progress bar that measure the light intensity The Image: One-half of the image will become gray scaled as the intensity increases. The Image Name: Font size will increase to support readability on high light intensity. 1. To add our first sensor Indicator, go to MainWindow.xaml and locate the left part layout grid (the one that contains a TextBlock, Sensor Data ). <TextBlock HorizontalAlignment="Center" Margin="0,10" VerticalAlignment="Top" FontFamily="Segoe UI" FontSize="13" Foreground="White" Text="Sensor Data"/> <Grid Margin="9,36,9,9"> <Grid.ColumnDefinitions> <ColumnDefinition Width="2*"/> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="0.4*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Border Grid.ColumnSpan="5" Grid.RowSpan="2" Background="Black" CornerRadius="2"/> 21

22 <TextBlock Grid.Column="0" Grid.Row="2" HorizontalAlignment="Center" Margin="4,0,4,10" VerticalAlignment="Center" Foreground="White" Text="LUM"/> <ProgressBar x:name="lightintensityprogressbar" Width="10" HorizontalAlignment="Center" Margin="0,8,0,5" Maximum="1" Minimum="0" Orientation="Vertical" Style="StaticResource SensorProgressBar" Value="Binding Path=LightSensor.Value.Intensity, Mode=OneWay, Converter=StaticResource LuminosityConverter"/> <Path Height="80" Grid.ColumnSpan="5" Grid.RowSpan="2" Margin="1,0" VerticalAlignment="Top" Data="M0.5,0.5L214.5, , ,168.4C197.7, , , , , ,197.3L0.5,197.8z" Stretch="Fill"> <Path.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="#04FFFFFF"/> <GradientStop Offset="0.1" Color="#10FFFFFF"/> <GradientStop Offset="1.0" Color="#18FFFFFF"/> </LinearGradientBrush> </Path.Fill> </Path> </Grid> 2. For our binding to work, we need to create a data converter between the values of the Sensor to the progress bar control. We do that by adding a converter class inside MainWIndow.xaml.cs. public class LuminosityConverter : IValueConverter #region IValueConverter Members public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) double d = System.Convert.ToDouble(value); return Math.Max(Math.Min(Math.Log(d, 10000), 1.0), 0.0); public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) throw new NotImplementedException(); #endregion 22

23 3. After we have created the LuminosityConverter class, we need to declare it as a resource. Go back to MainWindow.xaml and the local namespace declaration of the same namespace as the converter. <Window x:class="sensorhol.mainwindow" xmlns= xmlns:x= xmlns:local="clr-namespace:sensorhol" Title="MainWindow" WindowState="Maximized" Background="Black"> 4. Add a Resources section to the Window control. <Window.Resources> </Window.Resources> 5. Inside the resources section, declare the Converter resource. <local:luminosityconverter x:key="luminosityconverter" /> 6. Compile and run the application. You should see the LUM indicator responding to the Light Sensor. 7. Now connect this interaction to the rest of the elements with which we wished them to interact: a. First, change the font size of the image name. Once again a converter is needed to translate between the light values and font sizes. b. Then, locate the ImageName text block. (Note that we are binding the progress bar we implemented earlier). <TextBlock Foreground="White" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="Binding ElementName=LightIntensityProgressBar, Path=Value, Mode=OneWay, 23

24 Converter=StaticResource LuminosityToFontSizeConverter" Text="Binding ImageName, Mode=OneWay"/> 8. Go to code-behind the implement this converter public class LuminosityToFontSizeConverter : IValueConverter #region IValueConverter Members public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) double d = System.Convert.ToDouble(value); return 70.0 * d ; public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) throw new NotImplementedException(); #endregion 9. Now declare this converter as a resource. <Window.Resources> <local:luminosityconverter x:key="luminosityconverter" /> <local:luminositytofontsizeconverter x:key="luminositytofontsizeconverter" /> </Window.Resources> 10. Compile and run the code. The Image Name text should increase whenever the light intensifies. Now connect the image to the light indicator and apply a grayscale pixelshader effect to the image. 11. Start by adding a namespace to the PixelShaders that are located on your Starter solution. 24

25 <Window x:class="sensorhol.mainwindow" xmlns= xmlns:x= xmlns:local="clr-namespace:sensorhol" xmlns:pixelshaders="clr-namespace:sensorhol.pixelshaders" Title="MainWindow" WindowState="Maximized" Background="Black"> 12. Now can add the PixelShader element, and an OpacityMask to the second Image. <Image Source="Binding ImagePath" Stretch="Uniform" Margin="10"> </Image> <Image Source="Binding ImagePath" Stretch="Uniform" Margin="10"> <Image.Effect> <PixelShaders:GrayscaleEffect DesaturationFactor="Binding ElementName=LightIntensityProgressBar, Path=Value, Mode=OneWay, Converter=StaticResource InvertLuminosityConverter"/> </Image.Effect> <Image.OpacityMask> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Offset="Binding ElementName=OverlayAdjustmentSlider, Path=Value" Color="#0000"/> <GradientStop Offset="Binding ElementName=OverlayAdjustmentSlider, Path=Value" Color="#F000"/> </LinearGradientBrush> </Image.OpacityMask> </Image> 13. Again, implement a data converter between the light values and PixelShader values. public class InvertLuminosityConverter : IValueConverter #region IValueConverter Members public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) double d = System.Convert.ToDouble(value); return 1 - d; public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) throw new NotImplementedException(); 25

26 #endregion 14. As usual after we create the converter, we need to assign it as a resource. <Window.Resources> <local:luminosityconverter x:key="luminosityconverter" /> <local:luminositytofontsizeconverter x:key="luminositytofontsizeconverter" /> <local:invertluminosityconverter x:key="invertluminosityconverter" /> </Window.Resources> 15. Compile and run your code. Now you should be able to play with slider and have a portion of the image turned to grayscale due to interaction with the sensor. Task 7 Add Accelerometer Sensor Interaction with the UI (Optional) In this task, you will connect a 3D Accelerometer sensor to the UI. In addition to the accelerometer indicators on the left, the right part of the application rotates with each sensor movement. 1. First you will implement the X,Y,Z axis movements indicators: a. Inside MainWindow.xaml, locate the LightIntensityProgressBar. b. to this, add 3 more indicators. Since it is clear from the code that all 3 indicators bind to the same property, we need a way to distinguish between each indicator. that is the purpose of the Converter parameter that is used throughout the conversion process takes care of this. <TextBlock Grid.Column="0" Grid.Row="2" HorizontalAlignment="Center" Margin="4,0,4,10" VerticalAlignment="Center" Foreground="White" Text="LUM"/> <ProgressBar x:name="lightintensityprogressbar" Width="10" HorizontalAlignment="Center" Margin="0,8,0,5" Maximum="1" Minimum="0" 26

27 Orientation="Vertical" Style="StaticResource SensorProgressBar" Value="Binding Path=LightSensor.Value.Intensity, Mode=OneWay, Converter=StaticResource LuminosityConverter"/> <TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" Margin="4,0,4,10" VerticalAlignment="Center" Foreground="White" Text="X"/> <ProgressBar x:name="accelerometerx" Width="10" Grid.Column="1" HorizontalAlignment="Center" Margin="0,8,0,5" Maximum="1.3" Minimum="- 1.3" Orientation="Vertical" Style="StaticResource SensorProgressBar" Value="Binding Path=AcceleromaterSensor.Value, Mode=OneWay, Converter=StaticResource AccelerationConverter, ConverterParameter=X"/> <TextBlock Grid.Column="2" Grid.Row="2" HorizontalAlignment="Center" Margin="4,0,4,10" VerticalAlignment="Center" Foreground="White" Text="Y"/> <ProgressBar x:name="accelerometery" Width="10" Grid.Column="2" HorizontalAlignment="Center" Margin="0,8,0,5" Maximum="1.3" Minimum="- 1.3" Orientation="Vertical" Style="StaticResource SensorProgressBar" Value="Binding Path=AcceleromaterSensor.Value, Mode=OneWay, Converter=StaticResource AccelerationConverter, ConverterParameter=Y"/> <TextBlock Grid.Column="3" Grid.Row="2" HorizontalAlignment="Center" Margin="4,0,4,10" VerticalAlignment="Center" Foreground="White" Text="Z"/> <ProgressBar x:name="accelerometerz" Width="10" Grid.Column="3" HorizontalAlignment="Center" Margin="0,8,0,5" Maximum="1.3" Minimum="- 1.3" Orientation="Vertical" Style="StaticResource SensorProgressBar" Value="Binding Path=AcceleromaterSensor.Value, Mode=OneWay, Converter=StaticResource AccelerationConverter, ConverterParameter=Z"/> 2. Now we can add a data converter that makes use of the converter parameter, but first add the following using statement. using Microsoft.WindowsAPICodePack.Sensors; 3. Add the following code snippet. public class AccelerationConverter : IValueConverter 27

28 #region IValueConverter Members public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) Accelerometer3D.AccelerationAxis? axis = (Accelerometer3D.AccelerationAxis?)Enum.Parse(typeof(Acceleromete r3d.accelerationaxis), parameter as string); if (axis.hasvalue) var a3d = value as Accelerometer3D.Acceleration3D; if (a3d!= null) return a3d[axis.value]; return 0.0; public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) throw new NotImplementedException(); #endregion 4. Add the data converter resource declaration. <Window.Resources> <local:luminosityconverter x:key="luminosityconverter" /> <local:luminositytofontsizeconverter x:key="luminositytofontsizeconverter" /> <local:invertluminosityconverter x:key="invertluminosityconverter" /> <local:accelerationconverter x:key="accelerationconverter" /> </Window.Resources> Now we can make use of the 3D accelerometer sensor and rotate elements on the screen. We use WPF s rotate transform that uses degrees. A converter converts the X- and Y-axis of the Accelerometer to degrees. In order for the rotation to work properly, it must be centered on the middle of the element. That why we have the second converter that calculates the center of the element. 5. Add the following snippet to each of the images. 28

29 <Image.RenderTransform> <RotateTransform Angle="Binding Path=AcceleromaterSensor.Value, Mode=OneWay, Converter=StaticResource DegreesFromAcceleratorConverter" CenterX="Binding RelativeSource=RelativeSource AncestorType=x:Type Image, AncestorLevel=1, Path=ActualWidth, Converter=StaticResource DoubleSplitConverter" CenterY="Binding RelativeSource=RelativeSource AncestorType=x:Type Image, AncestorLevel=1, Path=ActualHeight, Converter=StaticResource DoubleSplitConverter" /> </Image.RenderTransform> 6. Add the following snippet to the Slider element (very similar to the one above). <Slider.RenderTransform> <RotateTransform Angle="Binding Path=AcceleromaterSensor.Value, Mode=OneWay, Converter=StaticResource DegreesFromAcceleratorConverter" CenterX="Binding RelativeSource=RelativeSource AncestorType=x:Type Slider, AncestorLevel=1, Path=ActualWidth, Converter=StaticResource DoubleSplitConverter" CenterY="Binding RelativeSource=RelativeSource AncestorType=x:Type Slider, AncestorLevel=1, Path=ActualHeight, Converter=StaticResource DoubleSplitConverter"/> </Slider.RenderTransform> 7. Implement the first converter, DegreesFromAcceleratorConverter. public class DegreesFromAcceleratorConverter : IValueConverter private double _prevx; private double _prevy; private const double _histcoeff = 0.6; private const double _threshold = 0.1; private bool _prevvaluesinit; #region IValueConverter Members 29

30 public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) var a3d = value as Accelerometer3D.Acceleration3D; if (a3d!= null) double x = a3d[accelerometer3d.accelerationaxis.x]; double y = a3d[accelerometer3d.accelerationaxis.y]; if (!_prevvaluesinit) _prevvaluesinit = true; _prevx = x; _prevy = y; if (Math.Abs(_prevX - x) < _threshold) x = _prevx; if (Math.Abs(_prevY - y) < _threshold) y = _prevy; _prevx = (_histcoeff * _prevx) + (1.0 - _histcoeff) * x; _prevy = (_histcoeff * _prevy) + (1.0 - _histcoeff) * y; double radians = Math.Atan2(_prevX, -_prevy); return radians * 180 / Math.PI; return 0.0; public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) throw new NotImplementedException(); #endregion 8. Now add the second converter. public class DoubleSplitConverter : IValueConverter #region IValueConverter Members public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) double doublevalue = System.Convert.ToDouble(value); 30

31 return doublevalue/2.0; public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) throw new NotImplementedException(); #endregion 9. All you have left to do is declare those converters as resources. <local:doublesplitconverter x:key="doublesplitconverter" /> <local:degreesfromacceleratorconverter x:key="degreesfromacceleratorconverter" /> 10. Compile and run your code. You should now be able to rotate the image along with it s slider. 31

32 You can find the final version of this project in the Final solution folder. Well Done! Summary Integrating Windows 7 Sensor support into your application provides the opportunity to increase the value of your applications, by making them more intelligent and aware of the environment. In this lab, you have created a WPF application from scratch and integrated different sensors for an amazing UI experience. 32

Hands-On Lab. Sensors & Location Platform - Native. Lab version: 1.0.0

Hands-On Lab. Sensors & Location Platform - Native. Lab version: 1.0.0 Hands-On Lab Sensors & Location Platform - Native Lab version: 1.0.0 Last updated: 12/3/2010 CONTENTS OVERVIEW... 3 EXERCISE 1: ADJUSTING FONT SIZE IN RESPONSE TO AMBIENT LIGHT INTENSITY... 5 Task 1 Adding

More information

Introduction to Data Templates and Value Converters in Silverlight

Introduction to Data Templates and Value Converters in Silverlight Introduction to Data Templates and Value Converters in Silverlight An overview of Data Templates and Value Converters by JeremyBytes.com Overview Business applications are all about data, and laying out

More information

RadGanttView For Silverlight and WPF

RadGanttView For Silverlight and WPF RadGanttView For Silverlight and WPF This tutorial will introduce RadGanttView, part of the Telerik suite of XAML controls. Setting Up The Project To begin, open Visual Studio and click on the Telerik

More information

CPSC Tutorial 5 WPF Applications

CPSC Tutorial 5 WPF Applications CPSC 481 - Tutorial 5 WPF Applications (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, David Ledo, Brennan Jones, and Sowmya Somanath) Today Horizontal Prototype WPF Applications Controls

More information

CPSC Tutorial 5

CPSC Tutorial 5 CPSC 481 - Tutorial 5 Assignment #2 and WPF (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, David Ledo, Brennan Jones, Sowmya Somanath, and Kevin Ta) Introduction Contact Info li26@ucalgary.ca

More information

Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver

Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver Windows 10 UWP Hands on Lab Lab 2: Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver 10240. 1. Select the Models folder and bring up the popup menu and

More information

Week 8: Data Binding Exercise (Bookstore)

Week 8: Data Binding Exercise (Bookstore) BCIS 4650 Week 8: Data Binding Exercise (Bookstore) Page 1 of 6 Page 2 of 6 XAML CODE FOR MainPage.xaml

More information

Name of Experiment: Country Database

Name of Experiment: Country Database Name of Experiment: Country Database Exp No: DB2 Background: Student should have basic knowledge of C#. Summary: Database Management is one of the key factors in any Mobile application development framework.

More information

RadPDFViewer For Silverlight and WPF

RadPDFViewer For Silverlight and WPF RadPDFViewer For Silverlight and WPF This tutorial will introduce the RadPDFViewer control, part of the Telerik suite of XAML controls Setting Up The Project To begin, open Visual Studio and click on the

More information

Workspace Desktop Edition Developer's Guide. Customize Views and Regions

Workspace Desktop Edition Developer's Guide. Customize Views and Regions Workspace Desktop Edition Developer's Guide Customize Views and Regions 11/27/2017 Customize Views and Regions Purpose: To provide information about customizable views and their regions. Contents 1 Customize

More information

Week 7: NavigationView Control Exercise

Week 7: NavigationView Control Exercise BCIS 4650 Week 7: NavigationView Control Exercise BUILD THE UI FIRST (ALWAYS). ================================================================================================ 1. Start with a New Project

More information

ComponentOne. Extended Library for UWP

ComponentOne. Extended Library for UWP ComponentOne Extended Library for UWP ComponentOne, a division of GrapeCity 201 South Highland Avenue, Third Floor Pittsburgh, PA 15206 USA Website: http://www.componentone.com Sales: sales@componentone.com

More information

sharpcorner.com/uploadfile/37db1d/4958/default.aspx?articleid=cb0b291c-52ae-4b80-a95c- 438d76fa1145

sharpcorner.com/uploadfile/37db1d/4958/default.aspx?articleid=cb0b291c-52ae-4b80-a95c- 438d76fa1145 Navigation in Silverlight -3 1. Introduction: In previous article we learn to navigate to another Silverlight page without using navigation framework, which is new feature in Silverlight 3. Read it Here:

More information

This tutorial is designed for software developers who want to learn how to develop quality applications with clean structure of code.

This tutorial is designed for software developers who want to learn how to develop quality applications with clean structure of code. About the Tutorial Every good developer wants and tries to create the most sophisticated applications to delight their users. Most of the times, developers achieve this on the first release of the application.

More information

Sparkline for WPF 1. ComponentOne. Sparkline for WPF

Sparkline for WPF 1. ComponentOne. Sparkline for WPF Sparkline for WPF 1 ComponentOne Sparkline for WPF Sparkline for WPF 2 ComponentOne, a division of GrapeCity 201 South Highland Avenue, Third Floor Pittsburgh, PA 15206 USA Website: http://www.componentone.com

More information

Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp

Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp COMP 585 Noteset #12 Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp. 46-48. WPF: More Code vs. Markup The apparently recommended way to use

More information

var xdoc = XDocument.Load(inStream);

var xdoc = XDocument.Load(inStream); Gradebook Sample App Summary: The goal of this project is to demonstrate how to share code across project types by using a Portable Class Library between a traditional Windows* Desktop application and

More information

The finished application DEMO ios-specific C# Android-specific C# Windows-specific C# Objective-C in XCode Java in Android Studio C# Shared Logic C# in Visual Studio ios codebase Android codebase Windows

More information

Hands-On Lab. Using Pivot and Panorama Controls

Hands-On Lab. Using Pivot and Panorama Controls Hands-On Lab Using Pivot and Panorama Controls Lab version: 1.0.0 Last updated: 12/8/2010 CONTENTS Overview... 3 Exercise 1: Introduction to Navigation in Windows Phone... 7 Task 1 Creating a Windows Phone

More information

Hands-On Lab. Using Bing Maps

Hands-On Lab. Using Bing Maps Hands-On Lab Using Bing Maps Lab version: 1.0.0 Last updated: 2/2/2011 CONTENTS Overview... 3 Exercise 1: Introduction to the Bing Map Control... 7 Task 1 Registering a Bing Maps Account... 7 Task 2 Working

More information

WPF Graphics and Multimedia

WPF Graphics and Multimedia csfp6_24_wpfgraphics.fm Page 1 Thursday, July 7, 2016 10:10 AM 24 WPF Graphics and Multimedia Objectives In this chapter you ll: Manipulate fonts. Draw basic WPF shapes. Use WPF brushes to customize the

More information

ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins. Wolfgang Kaiser

ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins. Wolfgang Kaiser ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins Wolfgang Kaiser Framework Elements - Recap Any Framework Element is an extensibility point - Controls (Button, Tool, and variants) - Hosted on

More information

Step4: Now, Drag and drop the Textbox, Button and Text block from the Toolbox.

Step4: Now, Drag and drop the Textbox, Button and Text block from the Toolbox. Name of Experiment: Display the Unicode for the key-board characters. Exp No:WP4 Background: Student should have a basic knowledge of C#. Summary: After going through this experiment, the student is aware

More information

New Insights into Process Deviations Using Multivariate. Control Charts

New Insights into Process Deviations Using Multivariate. Control Charts Abstract New Insights into Process Deviations Using Multivariate Control Charts In this paper we capture multivariate batch data in the form of letters of the alphabet, using a LEGO Mindstorms kit. With

More information

ArcGIS Pro SDK for.net UI Design for Accessibility. Charles Macleod

ArcGIS Pro SDK for.net UI Design for Accessibility. Charles Macleod ArcGIS Pro SDK for.net UI Design for Accessibility Charles Macleod Overview Styling - Light, Dark, High Contrast Accessibility Custom Styling* Add-in Styling Since1.4: Light and Dark Theme and High Contrast

More information

CPSC Tutorial 6

CPSC Tutorial 6 CPSC 481 - Tutorial 6 More WPF (based on previous tutorials by Alice Thudt, Fateme Rajabiyazdi, David Ledo, Brennan Jones, Sowmya Somanath, and Kevin Ta) Introduction Contact Info li26@ucalgary.ca Please

More information

Portable Class Libraries ---

Portable Class Libraries --- Portable Class Libraries --- Overview In this lab, you ll learn about Portable Class Libraries (PCLs). PCLs enable you to create managed assemblies that work on more than one.net Framework platform. Within

More information

Microsoft Corporation

Microsoft Corporation Microsoft Corporation http://www.jeff.wilcox.name/ 2 3 Display 480x800 QVGA Other resolutions in the future Capacitive touch 4+ contact points Sensors A-GPS, Accelerometer, Compass, Light Camera 5+ megapixels

More information

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer C# Tutorial Create a Motivational Quotes Viewer Application in Visual Studio In this tutorial we will create a fun little application for Microsoft Windows using Visual Studio. You can use any version

More information

Accurate study guides, High passing rate! IT TEST BOOK QUESTION & ANSWER. Ittestbook provides update free of charge in one year!

Accurate study guides, High passing rate! IT TEST BOOK QUESTION & ANSWER. Ittestbook provides update free of charge in one year! IT TEST BOOK QUESTION & ANSWER Ittestbook provides update free of charge in one year! Accurate study guides, High passing rate! Exam : 070-506 Title : TS: Microsoft Silverlight 4, Development Version :

More information

Weather forecast ( part 2 )

Weather forecast ( part 2 ) Weather forecast ( part 2 ) In the first part of this tutorial, I have consumed two webservices and tested them in a Silverlight project. In the second part, I will create a user interface and use some

More information

Advanced Programming C# Lecture 3. dr inż. Małgorzata Janik

Advanced Programming C# Lecture 3. dr inż. Małgorzata Janik Advanced Programming C# Lecture 3 dr inż. Małgorzata Janik majanik@if.pw.edu.pl Winter Semester 2017/2018 Windows Presentation Foundation Windows Presentation Foundation Allows for clear separation between

More information

windows-10-universal #windows- 10-universal

windows-10-universal #windows- 10-universal windows-10-universal #windows- 10-universal Table of Contents About 1 Chapter 1: Getting started with windows-10-universal 2 Remarks 2 Examples 2 Installation or Setup 2 Creating a new project (C# / XAML)

More information

WebFront for Service Manager

WebFront for Service Manager WebFront for Service Manager Authoring Guide Gridpro AB Rev: 2.10.6513 (System Center 2012) & 3.0.6513 (System Center 2016) Published: November 2017 Contents Purpose... 3 Introduction... 3 Limitations...

More information

Lecture # 6 Engr. Ali Javed 11th March, 2014

Lecture # 6 Engr. Ali Javed 11th March, 2014 Lecture # 6 Engr. Ali Javed 11 th March, 2014 Instructor s Information Instructor: Engr. Ali Javed Assistant Professor Department of Software Engineering U.E.T Taxila Email: ali.javed@uettaxila.edu.pk

More information

Hands-On Lab. Building Applications in Silverlight 4 Module 6: Printing the Schedule. Printing the Schedule

Hands-On Lab. Building Applications in Silverlight 4 Module 6: Printing the Schedule. Printing the Schedule Hands-On Lab Building Applications in Silverlight 4 Module 6: 1 P a g e Contents Introduction... 3 Exercise 1: on One Page... 4 Create the Printing ViewModel and View... 4 Hook up the Print Button... 7

More information

Authoring Guide v2.1 PATRIK SUNDQVIST

Authoring Guide v2.1 PATRIK SUNDQVIST 2012 Authoring Guide v2.1 PATRIK SUNDQVIST Purpose The purpose of this document is to provide assistance when customizing WebFront for Service Manager 2012. 1 TABLE OF CONTENTS 2 Introduction... 2 3 Limitations...

More information

Authoring Guide Gridpro AB Rev: Published: March 2014

Authoring Guide Gridpro AB Rev: Published: March 2014 Authoring Guide Gridpro AB Rev: 2.5.5197 Published: March 2014 Contents Purpose... 3 Introduction... 3 Limitations... 3 Prerequisites... 3 Customizing Forms... 4 Launching the Customization Editor... 4

More information

03 Model-View-ViewModel. Ben Riga

03 Model-View-ViewModel. Ben Riga 03 Model-View-ViewModel Ben Riga http://about.me/ben.riga Course Topics Building Apps for Both Windows 8 and Windows Phone 8 Jump Start 01 Comparing Windows 8 and Windows Phone 8 02 Basics of View Models

More information

Hands-On Lab. Hello Windows Phone

Hands-On Lab. Hello Windows Phone Hands-On Lab Hello Windows Phone Lab version: 1.1.0 Last updated: 12/8/2010 CONTENTS OVERVIEW... 3 EXERCISE 1: CREATING WINDOWS PHONE APPLICATIONS WITH MICROSOFT VISUAL STUDIO 2010 EXPRESS FOR WINDOWS

More information

WRITING THE MANAGEMENT SYSTEM APPLICATION

WRITING THE MANAGEMENT SYSTEM APPLICATION Chapter 10 WRITING THE MANAGEMENT SYSTEM APPLICATION We are going to write an application which will read and evaluate the data coming from our Arduino card reader application. We are going to make this

More information

Lesson 9: Exercise: Tip Calculator

Lesson 9: Exercise: Tip Calculator Lesson 9: Exercise: Tip Calculator In this lesson we ll build our first complete app, a Tip Calculator. It will help solve one of the fundamental problems that I have whenever I'm out to a restaurant,

More information

Developing Native Windows Phone 7 Applications for SharePoint

Developing Native Windows Phone 7 Applications for SharePoint Developing Native Windows Phone 7 Applications for SharePoint Steve Pietrek Cardinal Solutions About Cardinal OUR FOCUS: Enterprise Rich Internet Applications Mobile Solutions Portals & Collaboration Business

More information

Chromatic Remote Control Product Guide Executive Way, Suite A Frederick, MD 21704

Chromatic Remote Control Product Guide Executive Way, Suite A Frederick, MD 21704 Chromatic Remote Control Product Guide 7340 Executive Way, Suite A Frederick, MD 21704 Document Version: 2.1 December 2013 Contents 1 Introduction... 3 2 Accessing Chromatic Remote Control... 4 2.1 Configure

More information

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Hello World 2. Installation or Setup 3

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Hello World 2. Installation or Setup 3 xaml #xaml Table of Contents About 1 Chapter 1: Getting started with xaml 2 Remarks 2 Versions 2 Examples 2 Hello World 2 Installation or Setup 3 Chapter 2: Control Templates 5 Examples 5 Control Templates

More information

WPF and MVVM Study Guides

WPF and MVVM Study Guides 1. Introduction to WPF WPF and MVVM Study Guides https://msdn.microsoft.com/en-us/library/mt149842.aspx 2. Walkthrough: My First WPF Desktop Application https://msdn.microsoft.com/en-us/library/ms752299(v=vs.110).aspx

More information

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. Contents at a Glance About the Authors...

More information

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Installation or Setup 2. Hello World 2

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Installation or Setup 2. Hello World 2 xaml #xaml Table of Contents About 1 Chapter 1: Getting started with xaml 2 Remarks 2 Versions 2 Examples 2 Installation or Setup 2 Hello World 2 Chapter 2: Control Templates 5 Examples 5 Control Templates

More information

Course 2D_WPF: 2D-Computer Graphics with C# + WPF Chapter C1a: The Intro Project Written in XAML and C#

Course 2D_WPF: 2D-Computer Graphics with C# + WPF Chapter C1a: The Intro Project Written in XAML and C# 1 Course 2D_WPF: 2D-Computer Graphics with C# + WPF Chapter C1a: The Intro Project Written in XAML and C# An Empty Window Copyright by V. Miszalok, last update: 2011-02-08 Guidance for Visual C# 2010 Express,

More information

Master Code on Innovation and Inclusion

Master Code on Innovation and Inclusion Microsoft x HKEdCity: Master Code on Innovation and Inclusion Train-the-Trainers Workshop Writing Applications in C# with Visual Studio Content I. Getting the Tools Ready... 3 II. Getting Started with

More information

Windows Presentation Foundation. Jim Fawcett CSE687 Object Oriented Design Spring 2018

Windows Presentation Foundation. Jim Fawcett CSE687 Object Oriented Design Spring 2018 Windows Presentation Foundation Jim Fawcett CSE687 Object Oriented Design Spring 2018 References Pro C# 5 and the.net 4.5 Platform, Andrew Troelsen, Apress, 2012 Programming WPF, 2nd edition, Sells & Griffiths,

More information

Name of Experiment: Student Database

Name of Experiment: Student Database Name of Experiment: Student Database Exp No: DB1 Background: Student should have basic knowledge of C#. Summary: DBMS is a necessary requirement for any Mobile Application. We need to store and retrieve

More information

EL-USB-RT API Guide V1.0

EL-USB-RT API Guide V1.0 EL-USB-RT API Guide V1.0 Contents 1 Introduction 2 C++ Sample Dialog Application 3 C++ Sample Observer Pattern Application 4 C# Sample Application 4.1 Capturing USB Device Connect \ Disconnect Events 5

More information

Styles and Control Templates

Styles and Control Templates Chapter CHAPTER 5 5 Styles and Control Templates In a word processing document, a style is a set of properties to be applied to ranges of content e.g., text, images, etc. For example, the name of the style

More information

Exam Name: TS: Microsoft.NET Framework 3.5, Windows Presentation Foundation Application

Exam Name: TS: Microsoft.NET Framework 3.5, Windows Presentation Foundation Application Vendor: Microsoft Exam Code: 70-502 Exam Name: TS: Microsoft.NET Framework 3.5, Windows Presentation Foundation Application Development Version: DEMO 1: You are creating a Windows Presentation Foundation

More information

Hands-On Lab. Taskbar -.NET (WPF) Lab version: 1.0.0

Hands-On Lab. Taskbar -.NET (WPF) Lab version: 1.0.0 Hands-On Lab Taskbar -.NET (WPF) Lab version: 1.0.0 Last updated: 12/3/2010 CONTENTS OVERVIEW... 3 EXERCISE: EXPERIMENT WITH THE NEW WINDOWS 7 TASKBAR FEATURES... 5 Task 1 Using Taskbar Overlay Icons...

More information

Week 6: First XAML Control Exercise

Week 6: First XAML Control Exercise BCIS 4650 Week 6: First XAML Control Exercise The controls you will use are: Blank App (Universal Windows), which contains a Grid control by default StackPanel (acts as a container for CheckBoxes and RadioButtons)

More information

Mobile Computing Xamarin Data Binding MVVM Pattern

Mobile Computing Xamarin Data Binding MVVM Pattern Xamarin Data Binding MVVM Pattern APM@FEUP 1 Data Binding In simple apps Get and set properties of controls is done explicitly in the code behind entry1.text = Hello, world! ; For complex or big apps This

More information

Hands-On Lab. Building Applications in Silverlight 4 Module 7: Event Administrator Dashboard with Out of Browser, Toasts and Native Integration

Hands-On Lab. Building Applications in Silverlight 4 Module 7: Event Administrator Dashboard with Out of Browser, Toasts and Native Integration Hands-On Lab Building Applications in Silverlight 4 Module 7: with Out of Browser, Toasts and Native Integration 1 P a g e Contents Introduction... 3 Exercise 1: Adding an Out of Browser Application...

More information

Developing Desktop Apps for Ultrabook Devices in Windows* 8: Adapting Existing Apps By Paul Ferrill

Developing Desktop Apps for Ultrabook Devices in Windows* 8: Adapting Existing Apps By Paul Ferrill Developing Desktop Apps for Ultrabook Devices in Windows* 8: Adapting Existing Apps By Paul Ferrill Microsoft introduced the Extensible Application Markup Language (XAML) in conjunction with the release

More information

Mobile Computing. Xamarin Data Binding MVVM Pattern. Data Binding. XAML binding example. Target Views. In simple apps. For complex or big apps

Mobile Computing. Xamarin Data Binding MVVM Pattern. Data Binding. XAML binding example. Target Views. In simple apps. For complex or big apps APM@FEUP Xamarin Data Binding MVVM Pattern 1 Data Binding In simple apps Get and set properties of controls is done explicitly in the code behind entry1.text = Hello, world! ; For complex or big apps This

More information

This walkthrough assumes you have completed the Getting Started walkthrough and the first lift and shift walkthrough.

This walkthrough assumes you have completed the Getting Started walkthrough and the first lift and shift walkthrough. Azure Developer Immersion In this walkthrough, you are going to put the web API presented by the rgroup app into an Azure API App. Doing this will enable the use of an authentication model which can support

More information

ArcGIS Pro SDK for.net Beginning Pro Customization. Charles Macleod

ArcGIS Pro SDK for.net Beginning Pro Customization. Charles Macleod ArcGIS Pro SDK for.net Beginning Pro Customization Charles Macleod Session Overview Extensibility patterns - Add-ins - Configurations Primary API Patterns - QueuedTask and Asynchronous Programming - async

More information

ComponentOne. HyperPanel for WPF

ComponentOne. HyperPanel for WPF ComponentOne HyperPanel for WPF Copyright 1987-2012 GrapeCity, Inc. All rights reserved. ComponentOne, a division of GrapeCity 201 South Highland Avenue, Third Floor Pittsburgh, PA 15206 USA Internet:

More information

Visão Computacional: Reconhecimento da Mão Humana e Seus Movimentos. Licenciatura em Gestão de Sistemas e Computação. Visão Computacional:

Visão Computacional: Reconhecimento da Mão Humana e Seus Movimentos. Licenciatura em Gestão de Sistemas e Computação. Visão Computacional: Visão Computacional: Reconhecimento da Mão Humana e Seus Movimentos Licenciatura em Gestão de Sistemas e Computação Visão Computacional: Reconhecimento da Mão Humana e Seus Movimentos Projeto Final de

More information

ComponentOne. PdfViewer for WPF and Silverlight

ComponentOne. PdfViewer for WPF and Silverlight ComponentOne PdfViewer for WPF and Silverlight GrapeCity US GrapeCity 201 South Highland Avenue, Suite 301 Pittsburgh, PA 15206 Tel: 1.800.858.2739 412.681.4343 Fax: 412.681.4384 Website: https://www.grapecity.com/en/

More information

Course 3D_WPF: 3D-Computer Graphics with C# + WPF Chapter C3: Dice

Course 3D_WPF: 3D-Computer Graphics with C# + WPF Chapter C3: Dice 1 Course 3D_WPF: 3D-Computer Graphics with C# + WPF Chapter C3: Dice Front face All faces CheckBoxes Camera sliders Corrugated faces Front face Copyright by V. Miszalok, last update: 2010-01-08 Guidance

More information

ArcGIS Pro SDK for.net: UI Design and MVVM

ArcGIS Pro SDK for.net: UI Design and MVVM Esri Developer Summit March 8 11, 2016 Palm Springs, CA ArcGIS Pro SDK for.net: UI Design and MVVM Charlie Macleod, Wolf Kaiser Important Customization Patterns for the Pro SDK MVVM Hooking Pro Commands

More information

The Model provides underlying data, sometimes involving file or web accesses.

The Model provides underlying data, sometimes involving file or web accesses. Chapter 18 MVVM Can you remember your earliest experiences with programming? It s likely that your main goal was just getting the program working, and then getting it working correctly. You probably didn

More information

NE.15 Data Binding In Windows Presentation Foundation

NE.15 Data Binding In Windows Presentation Foundation NE.15 Data Binding In Windows Presentation Foundation Brian Noyes Chief Architect IDesign Inc (www.idesign.net) 1 About Brian Chief Architect, IDesignInc. (www.idesign.net) Microsoft Regional Director/MVP

More information

Developing Desktop Apps for Ultrabook Devices in Windows 8*: Getting Started

Developing Desktop Apps for Ultrabook Devices in Windows 8*: Getting Started Developing Desktop Apps for Ultrabook Devices in Windows 8*: Getting Started By Paul Ferrill The Ultrabook provides a rich set of sensor capabilities to enhance a wide range of applications. It also includes

More information

Quick Guide for the ServoWorks.NET API 2010/7/13

Quick Guide for the ServoWorks.NET API 2010/7/13 Quick Guide for the ServoWorks.NET API 2010/7/13 This document will guide you through creating a simple sample application that jogs axis 1 in a single direction using Soft Servo Systems ServoWorks.NET

More information

Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C5: The Complete Code of PathAnimation. Copyright by V. Miszalok, last update:

Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C5: The Complete Code of PathAnimation. Copyright by V. Miszalok, last update: 1 Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C5: The Complete Code of PathAnimation Preliminaries Page.XAML Page.xaml.cs Copyright by V. Miszalok, last update: 30-01-2009 Install 1) Visual

More information

.NET Framework, C# and a little bit of WPF. Ivan Bernabucci University Roma TRE

.NET Framework, C# and a little bit of WPF. Ivan Bernabucci University Roma TRE 2 Ivan Bernabucci University Roma TRE i.bernabucci@uniroma3.it OVERVIEW What is.net? What is FCL? What is CLR? What is C#? Basic Expressions and Operators Creating Project with Visual Studio Exploring

More information

Skinning Manual v1.0. Skinning Example

Skinning Manual v1.0. Skinning Example Skinning Manual v1.0 Introduction Centroid Skinning, available in CNC11 v3.15 r24+ for Mill and Lathe, allows developers to create their own front-end or skin for their application. Skinning allows developers

More information

Microsoft Windows Apps Dev w/microsoft.net Framework 4. Download Full Version :

Microsoft Windows Apps Dev w/microsoft.net Framework 4. Download Full Version : Microsoft 70-511 Windows Apps Dev w/microsoft.net Framework 4 Download Full Version : https://killexams.com/pass4sure/exam-detail/70-511 Answer: A, C QUESTION: 215 You develop a Windows Presentation Foundation

More information

Windows Presentation Foundation Programming Using C#

Windows Presentation Foundation Programming Using C# Windows Presentation Foundation Programming Using C# Duration: 35 hours Price: $750 Delivery Option: Attend training via an on-demand, self-paced platform paired with personal instructor facilitation.

More information

In this exercise you will gain hands-on experience using STK X to embed STK functionality in a container application created with C#.

In this exercise you will gain hands-on experience using STK X to embed STK functionality in a container application created with C#. STK X Tutorial - C# In this exercise you will gain hands-on experience using STK X to embed STK functionality in a container application created with C#. CONTENTS TUTORIAL SOURCE CODE... 1 CREATE THE PROJECT...

More information

ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins. Wolfgang Kaiser

ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins. Wolfgang Kaiser ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins Wolfgang Kaiser Session Overview MVVM Model View ViewModel - View and View Model Implementation in Pro - Dockpane Example - MVVM concepts - Multi

More information

Controls WPF. Windows Programming. Lecture 8-1. Krzysztof Mossakowski Faculty of Mathematics and Information Science

Controls WPF. Windows Programming. Lecture 8-1. Krzysztof Mossakowski Faculty of Mathematics and Information Science WPF Windows Programming Lecture 8-1 Controls Content Models There are 4 content models used by controls: ContentControl contains a single item Lecture 8-2 used by: Button, ButtonBase, CheckBox, ComboBoxItem,

More information

Launchers and Choosers Hands-on Lab. Hands-On Lab. Launchers and Choosers. Lab version: Last updated: 12/8/2010. Page 1

Launchers and Choosers Hands-on Lab. Hands-On Lab. Launchers and Choosers. Lab version: Last updated: 12/8/2010. Page 1 Hands-On Lab Launchers and Choosers Lab version: 1.0.0 Last updated: 12/8/2010 Page 1 CONTENTS Overview... 3 Exercise 1: Introduction to the Windows Phone Launchers... 8 Task 1 Adding and Navigating to

More information

XAML - BUTTON. The Button class represents the most basic type of button control. The hierarchical inheritance of Button class is as follows

XAML - BUTTON. The Button class represents the most basic type of button control. The hierarchical inheritance of Button class is as follows http://www.tutorialspoint.com/xaml/xaml_button.htm XAML - BUTTON Copyright tutorialspoint.com The Button class represents the most basic type of button control. The hierarchical inheritance of Button class

More information

Microsoft.BrainDump v by.Gabry.53q

Microsoft.BrainDump v by.Gabry.53q Microsoft.BrainDump.70-511.v2012-10-03.by.Gabry.53q Number: 000-000 Passing Score: 800 Time Limit: 120 min File Version: 1.0 I corrected some questions in previous vce(provided by Pit). Exam A QUESTION

More information

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear.

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear. 4 Programming with C#.NET 1 Camera The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear. Begin by loading Microsoft Visual Studio

More information

Windows Phone 8 Game Development

Windows Phone 8 Game Development Windows Phone 8 Game Development Marcin Jamro Chapter No. 8 "Maps, Geolocation, and Augmented Reality" In this package, you will find: A Biography of the author of the book A preview chapter from the book,

More information

ArcGIS Pro Extensibility - Building and Deploying Addins with the new DotNet SDK

ArcGIS Pro Extensibility - Building and Deploying Addins with the new DotNet SDK ArcGIS Pro Extensibility - Building and Deploying Addins with the new DotNet SDK Charlie Macleod - Esri Esri UC 2014 Demo Theater New at 10.3 is the ArcGIS Pro Application - Extensibility is provided by

More information

Click on the empty form and apply the following options to the properties Windows.

Click on the empty form and apply the following options to the properties Windows. Start New Project In Visual Studio Choose C# Windows Form Application Name it SpaceInvaders and Click OK. Click on the empty form and apply the following options to the properties Windows. This is the

More information

SAMPLE CHAPTER. C# and XAML. Pete Brown MANNING

SAMPLE CHAPTER. C# and XAML. Pete Brown MANNING SAMPLE CHAPTER C# and XAML Pete Brown MANNING Windows Store App Development by Pete Brown Chapter 18 Copyright 2013 Manning Publications brief contents 1 Hello, Modern Windows 1 2 The Modern UI 19 3 The

More information

Interface Builders and Interface Description Languages

Interface Builders and Interface Description Languages Interface Builders and Interface Description Languages Interface Builders (IB) and Interface Description Languages (IDL) enable Drag and Drop construction of GUI's are part of man;y Visual Studio(2013)

More information

04 Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio. Ben Riga

04 Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio. Ben Riga 04 Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga http://about.me/ben.riga Course Topics Building Apps for Both Windows 8 and Windows Phone 8 Jump Start 01 Comparing Windows

More information

S AMPLE CHAPTER IN ACTION. Timothy Binkley-Jones Massimo Perga Michael Sync MANNING

S AMPLE CHAPTER IN ACTION. Timothy Binkley-Jones Massimo Perga Michael Sync MANNING S AMPLE CHAPTER IN ACTION Timothy Binkley-Jones Massimo Perga Michael Sync MANNING Windows Phone 7 in Action by Timothy Binkley-Jones Massimo Perga Michael Sync Chapter 8 Copyright 2013 Manning Publications

More information

WebAqua.NET 2.0 White Paper

WebAqua.NET 2.0 White Paper WebAqua.NET 2.0 White Paper Table of Contents Overview... 3 Technology... 4 Silverlight 2.0... 4 ASP.NET... 6 Licensing and Deployment for Silverlight 2.0... 7 Runtime Licensing... 7 Deployment... 8 Design-time

More information

SCICHART v2.0 (BETA 2)

SCICHART v2.0 (BETA 2) SCICHART v2.0 (BETA 2) Release Note A letter from the SciChart Team A huge thank you to those who have downloaded the rough-around-the-edges SciChart v2.0 Beta 1! We have a second beta now with some urgent

More information

CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom

CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom CS3240 Lab SEM 1 2009/2010 Page 1 Overview In this lab, you will get familiarized with interactive media elements such

More information

EXAM TS:Windows Apps Dev w/microsoft.net Framework 4((C# and VB) Buy Full Product.

EXAM TS:Windows Apps Dev w/microsoft.net Framework 4((C# and VB) Buy Full Product. Microsoft EXAM - 70-511 TS:Windows Apps Dev w/microsoft.net Framework 4((C# and VB) Buy Full Product http://www.examskey.com/70-511.html Examskey Microsoft 70-511 exam demo product is here for you to test

More information

IAP C# Lecture 5 XAML and the Windows Presentation Foundation. Geza Kovacs

IAP C# Lecture 5 XAML and the Windows Presentation Foundation. Geza Kovacs IAP C# Lecture 5 XAML and the Windows Presentation Foundation Geza Kovacs What is Windows Presentation Foundation (WPF)? A toolkit for building graphical user interfaces (GUI) for an application Ships

More information

CALCULATOR APPLICATION

CALCULATOR APPLICATION CALCULATOR APPLICATION Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;

More information

Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C1: The Intro Project

Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C1: The Intro Project 1 Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C1: The Intro Project Copyright by V. Miszalok, last update: 16-10-2008 Preliminaries Version 01: Page.XAML Version 02: Page.XAML Version 03:

More information

Migrating to Windows Phone

Migrating to Windows Phone BOOKS FOR PROFESSIONALS BY PROFESSIONALS Liberty Blankenburg RELATED Migrating to Windows Phone Upgrade your existing programming knowledge and begin developing for the Windows Phone with Migrating to

More information

You can call the project anything you like I will be calling this one project slide show.

You can call the project anything you like I will be calling this one project slide show. C# Tutorial Load all images from a folder Slide Show In this tutorial we will see how to create a C# slide show where you load everything from a single folder and view them through a timer. This exercise

More information