Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将属性从MainWindow更新为userControl_C#_Wpf_User Controls_Inotifypropertychanged - Fatal编程技术网

C# 将属性从MainWindow更新为userControl

C# 将属性从MainWindow更新为userControl,c#,wpf,user-controls,inotifypropertychanged,C#,Wpf,User Controls,Inotifypropertychanged,我在主窗口ZoomSlider中定义了属性,即数据绑定到Slider 在UserControl上,我有一个椭圆,它的高度以滑块值为界 主窗口代码 我成功地在UserControl中获得了默认的slider值,但是当slider的value属性更改时,它不会反映在UserControl中 那么,底线是如何将更新的滑块值获取到UserControl Ellipse 注: UserControl绑定到UserControl Viewmodel,MainWindow到Window Viewmodel也是

我在主窗口ZoomSlider中定义了属性,即数据绑定到Slider

在UserControl上,我有一个椭圆,它的高度以滑块值为界

主窗口代码

我成功地在UserControl中获得了默认的slider值,但是当slider的value属性更改时,它不会反映在UserControl中

那么,底线是如何将更新的滑块值获取到UserControl Ellipse

注:

UserControl绑定到UserControl Viewmodel,MainWindow到Window Viewmodel也是如此


感谢您的帮助

ZoomSlider应具有DependencyProperty作为支持字段以启用绑定

public double ZoomSlider
{
   get { return (double)GetValue(ZoomSliderProperty); }
   set { SetValue(ZoomSliderProperty, value); }
}

// Using a DependencyProperty as the backing store for ZoomSlider.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty ZoomSliderProperty =
            DependencyProperty.Register("ZoomSlider", typeof(double), typeof(MainWindow), new PropertyMetadata(2d));
在此处放置转换器并检查。。。
<Ellipse  Stroke="Black">
   <Ellipse.Height>
      <MultiBinding Converter="{StaticResource zoomConverter}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True">

           <Binding Path="Dia" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True"/>

           <Binding RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type Window}}" Path="ZoomSlider" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" 
         NotifyOnSourceUpdated="True" PresentationTraceSources.TraceLevel="High"/>

      </MultiBinding> 
private double zoomSlider = 2;

public double ZoomSlider
{
    get { return zoomSlider; }
    set
    {
        zoomSlider = value;
        NotifyPropertyChanged("ZoomSlider");
    }
}
public double ZoomSlider
{
   get { return (double)GetValue(ZoomSliderProperty); }
   set { SetValue(ZoomSliderProperty, value); }
}

// Using a DependencyProperty as the backing store for ZoomSlider.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty ZoomSliderProperty =
            DependencyProperty.Register("ZoomSlider", typeof(double), typeof(MainWindow), new PropertyMetadata(2d));