//アプリが表示された直後 private void MainWindow_ContentRendered(object sender, EventArgs e) { //Image拡大表示の補間法指定、今回はニアレストネイバー法 RenderOptions.SetBitmapScalingMode(MyImage1, BitmapScalingMode.NearestNeighbor); //ScaleTransform作成してImageのRenderTransformに指定 //これをしないと拡大できない var st = new ScaleTransform(); MyImage1.RenderTransform = st; //ここからBinding //ソース SliderのValue //ターゲット ImageのScaleTransformのXとY var b = new Binding(); b.Source = SliderScale; b.Path = new PropertyPath(Slider.ValueProperty); BindingOperations.SetBinding(st, ScaleTransform.ScaleXProperty, b); BindingOperations.SetBinding(st, ScaleTransform.ScaleYProperty, b); //ソース Slider.Value //ターゲット CanvasのWidth //Canvas.Width = Slider.Value * Image.ActualWidthをにするためにConverter指定 //ParameterにImage.Width b = new Binding(); b.Source = SliderScale; b.Path = new PropertyPath(Slider.ValueProperty); b.ConverterParameter = MyImage1.ActualWidth; b.Converter = new MyConverter(); MyCanvas1.SetBinding(WidthProperty, b); //↑のHeight版 b = new Binding(); b.Source = SliderScale; b.Path = new PropertyPath(Slider.ValueProperty); b.ConverterParameter = MyImage1.ActualHeight; b.Converter = new MyConverter(); MyCanvas1.SetBinding(HeightProperty, b); }
/*-------------------------- PLAY -------------------------------*/ private void Play(object sender, RoutedEventArgs e) { player11.Focusable = false; player22.Focusable = false; MyCanvas1.Focus(); position(); positionC = true; _timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate { if (_time == TimeSpan.Zero) { _timer.Stop(); stopWatch.Start(); dispatcherTimer.Start(); } Countdown.Text = _time.ToString("c"); _time = _time.Add(TimeSpan.FromSeconds(-1)); }, Application.Current.Dispatcher); _timer.Start(); btn_play.IsEnabled = false; }
//アプリが表示された直後 private void MainWindow_ContentRendered(object sender, EventArgs e) { //ソース Slider.Value //ターゲット CanvasのWidth //Canvas.Width = Slider.Value * Image.ActualWidthをにするためにConverter指定 //ParameterにImage.Width var b = new Binding(); b.Source = SliderScale; b.Path = new PropertyPath(Slider.ValueProperty); b.ConverterParameter = MyImage1.ActualWidth; b.Converter = new MyConverter(); MyCanvas1.SetBinding(WidthProperty, b); //↑のHeight版 b = new Binding(); b.Source = SliderScale; b.Path = new PropertyPath(Slider.ValueProperty); b.ConverterParameter = MyImage1.ActualHeight; b.Converter = new MyConverter(); MyCanvas1.SetBinding(HeightProperty, b); }