Пример #1
0
        private void I2CCheck(object state)
        {
            string xText, yText, zText, wText, meas1doneText;
            string statusText;

            try
            {
                double waterHeight = _aquaI2C.GetWaterHeight();

                meas1doneText = string.Format("Meas1 Done = {0:F3}", _aquaI2C.DataIn.DataLSB);

                xText      = string.Format("Data1: {0:F}", _aquaI2C.FinalCapMeasure1);
                yText      = string.Format("Data2: {0:F}", _aquaI2C.FinalCapMeasure2);
                zText      = string.Format("Data3: {0:F}", _aquaI2C.FinalCapMeasure3);
                wText      = string.Format("Data4: {0:F}", _aquaI2C.FinalCapMeasure1);
                statusText = string.Format("Cpf: {0:F}", waterHeight);
            }
            catch (Exception ex)
            {
                xText         = "Data1: Error";
                yText         = "Data2: Error";
                zText         = "Data3: Error";
                wText         = "Data4: Error";
                meas1doneText = "DataMeas: Err";
                statusText    = "Failed to read from FDC1004: " + ex.Message;
            }

            /* UI updates must be invoked on the UI thread */
            Windows.Foundation.IAsyncAction task = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                I2CData1.Text         = xText;
                I2CData2.Text         = yText;
                I2CData3.Text         = zText;
                I2CData4.Text         = wText;
                Measurement1Done.Text = meas1doneText;
                Text_Status.Text      = statusText;
            });
        }
Пример #2
0
        public object ConvertToNative(Brush brush, object context)
        {
            winMedia.Brush winBrush = null;

            // SolidColorBrush
            if (brush is SolidColorBrush)
            {
                SolidColorBrush xamBrush = brush as SolidColorBrush;

                winBrush = new winMedia.SolidColorBrush
                {
                    Color = ConvertColor(xamBrush.Color)
                };
            }

            // LinearGradientBrush
            else if (brush is LinearGradientBrush)
            {
                LinearGradientBrush xamBrush = brush as LinearGradientBrush;

                winBrush = new winMedia.LinearGradientBrush
                {
                    StartPoint   = ConvertPoint(xamBrush.StartPoint),
                    EndPoint     = ConvertPoint(xamBrush.EndPoint),
                    SpreadMethod = ConvertGradientSpread(xamBrush.SpreadMethod)
                };

                foreach (GradientStop xamGradientStop in xamBrush.GradientStops)
                {
                    winMedia.GradientStop winGradientStop = new winMedia.GradientStop
                    {
                        Color  = ConvertColor(xamGradientStop.Color),
                        Offset = xamGradientStop.Offset
                    };

                    (winBrush as winMedia.LinearGradientBrush).GradientStops.Add(winGradientStop);
                }
            }

            else if (brush is ImageBrush)
            {
                ImageBrush xamBrush = brush as ImageBrush;

                winBrush = new winMedia.ImageBrush
                {
                    Stretch    = (winMedia.Stretch)(int) xamBrush.Stretch,
                    AlignmentX = (winMedia.AlignmentX)(int) xamBrush.AlignmentX,
                    AlignmentY = (winMedia.AlignmentY)(int) xamBrush.AlignmentY,
                };

                ImageSource xamImageSource = (brush as ImageBrush).ImageSource;

                if (xamImageSource != null)
                {
                    IImageSourceHandler handler = null;

                    if (xamImageSource.GetType() == typeof(FileImageSource))
                    {
                        handler = new FileImageSourceHandler();
                    }
                    else if (xamImageSource.GetType() == typeof(StreamImageSource))
                    {
                        handler = new StreamImageSourceHandler();
                    }
                    else if (xamImageSource.GetType() == typeof(UriImageSource))
                    {
                        handler = new UriImageSourceHandler();
                    }

                    if (handler != null)
                    {
                        Task <winMedia.ImageSource> winImageSourceTask = handler.LoadImageAsync(xamImageSource);

                        winImageSourceTask.ContinueWith((task) =>
                        {
                            winFound.IAsyncAction asyncAction = winBrush.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                (winBrush as winMedia.ImageBrush).ImageSource = task.Result;
                            });
                        });
                    }
                }
            }

            if (winBrush != null)
            {
                winBrush.Transform = brush.Transform?.GetNativeObject() as winMedia.MatrixTransform;

                // TODO: RelativeTransform and Opacity
            }

            return(winBrush);
        }