Пример #1
0
        private StackPanel BuildColorTemperturePanel()
        {
            var slider = BuildSlider(null, null);

            slider.Value = 0;

            slider.ManipulationCompleted += async(sender, e) =>
            {
                var target = ParameterUtil.AsValidColorTemperture((int)slider.Value, Status);
                slider.Value = target;
                try
                {
                    await Api.Camera.SetWhiteBalanceAsync(new WhiteBalance { Mode = Status.WhiteBalance.Current, ColorTemperature = target });
                }
                catch (RemoteApiException ex)
                {
                    DebugUtil.Log(() => "Failed to set color temperture: " + ex.StatusCode);
                }
                catch (NullReferenceException ex)
                {
                    DebugUtil.Log(() => "Failed to set color temperture: " + ex.Message);
                }
            };

            var indicator = new TextBlock
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                Style  = Application.Current.Resources["BaseTextBlockStyle"] as Style,
                Margin = new Thickness(10, 22, 0, 0),
            };

            indicator.SetBinding(TextBlock.TextProperty, new Binding()
            {
                Source = Status,
                Path   = new PropertyPath(nameof(CameraStatus.ColorTemperture)),
                Mode   = BindingMode.OneWay,
            });

            slider.SetBinding(RangeBase.ValueProperty, new Binding()
            {
                Source = Status,
                Path   = new PropertyPath(nameof(CameraStatus.ColorTemperture)),
                Mode   = BindingMode.TwoWay
            });

            ColorTempertureSlider = slider;

            var parent = BuildBasicPanel(SystemUtil.GetStringResource("WB_ColorTemperture"));

            (parent.Children[0] as StackPanel).Children.Add(indicator);
            parent.Children.Add(slider);
            parent.SetBinding(UIElement.VisibilityProperty, new Binding()
            {
                Source    = DataSource,
                Path      = new PropertyPath(nameof(ControlPanelDataSource.IsAvailableColorTemperture)),
                Mode      = BindingMode.OneWay,
                Converter = new BoolToVisibilityConverter()
            });

            return(parent);
        }