我有在MainWindow“ZoomSlider”中定义的属性,即数据绑定到Slider
。从MainWindow更新属性到userControl
在UserControl
我有一个Ellipse
,使其高度限制为Slider
值。
主窗口代码
<Slider
Grid.Column="4"
Value="{Binding ElementName=MainWindow,Path=ZoomSlider,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}"
Maximum="46"
Minimum=".1"
LargeChange=".1"
Ticks="0,1,5"
TickPlacement="BottomRight"
SmallChange=".1"
Height="22"
Width="75"
Margin="0"
HorizontalAlignment="Right"
VerticalAlignment="Bottom">
</Slider>
<!--Content Control is the Host of a userControl which iam Setting dynamically at runtime-->
<ContentControl Name="content" BorderThickness="1"
Content="{Binding CurrentViewModel,Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}">
</ContentControl>
用户控件代码
<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>
主窗口C#代码
private double zoomSlider = 2;
public double ZoomSlider
{
get { return zoomSlider; }
set
{
zoomSlider = value;
NotifyPropertyChanged("ZoomSlider");
}
}
我成功地获取默认滑块值在UserControl
,但是当Slider
的价值属性更改其是没有得到体现在UserControl
。
因此,底线如何更新滑块值到达UserControl
Ellipse
注:
UserControl
绑定到用户控件视图模型,所以是主窗口到窗口视图模型
任何帮助感谢!
在此放置的转换器'<绑定的RelativeSource = “{的RelativeSource FindAncestor,AncestorType = {X:类型窗口}}” 路径=“ZoomSlider “Mode =”TwoWay“UpdateSourceTrigger =”PropertyChanged“ NotifyOnSourceUpdated =”True“PresentationTraceSources.TraceLevel =”High“/>'并检查... – Sankarann