简体   繁体   中英

Binding between two xaml windows

I have the following slider:

<Slider x:Name="uiScaleSlider" Value="1" Minimum="0.5" Maximum="1.5" />

Which affects a scale transformation:

 <ScaleTransform  
      CenterX="0" 
      CenterY="0" 
      ScaleX="{Binding ElementName=uiScaleSlider,Path=Value}"  
      ScaleY="{Binding ElementName=uiScaleSlider,Path=Value}" />

However they each are on seperate windows (ie the slider is on an 'options' screen and the scaletransform is on the main window).

How do I bind the two windows so the slider and scaletransform can connect and therefore operate?

You can manage to have App variable, which can be shared among the views. I'm not sure its cleaner way. But i have something similar in the production.

In you App.xaml.cs

Create your model for the binding.

private static int _minimumValue;
public static int MinimumValue
 {
        get
        {
            return _minimumValue;
        }
        set
        {
            _minimumValue = value;
            RaisePropertyChangedStatic("MinimumValue");
        }
}

Option Screen Xaml should look like this

<Slider x:Name="uiScaleSlider" Value="1" 
        Minimum={Binding MinimumValue, Source="{x:Static Application.Current}" />

MainWindow.Xaml

<ScaleTransform  
  CenterX="0" 
  CenterY="0" 
  ScaleX={Binding MinimumValue, Source="{x:Static Application.Current}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM