本文介绍了如何在usercontrol中引用控件以进行绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人请帮助我.
Hi,
some one please help me.
<zb:ZoomBoxPanel ZoomMode="FitPage" x:Name="zoomBox" Grid.Row="2" MinZoom="20" MaxZoom="300" MouseMode="Pan" WheelMode="Zoom">
<Border BorderThickness="1" BorderBrush="Black">
<Button Width="100" Height="200" HorizontalAlignment="Left" VerticalAlignment="Top"></Button>
</Border>
</zb:ZoomBoxPanel>
<zb:ZoomBoxSlider Margin="10" Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Top"
ZoomBox="{Binding ElementName=zoomBox}" />
上面的代码可以正常工作,因为ZoomBoxPanel
和ZoomBoxSlider
都在同一窗口中.
但是如果我在其中放置ZoomBoxPanel
的地方创建一个UserControl
,现在创建的UserControl
和ZoomBoxSlider
在同一个窗口中,现在我该如何将ZoomBoxSlider
的zoombox
属性绑定到创建的UserControl
的ZoomBoxPanel
控件
谢谢和问候
Easwar
the above code works fine as the both ZoomBoxPanel
and ZoomBoxSlider
are in same window.
but if i create one UserControl
where i am going to place the ZoomBoxPanel
and now the created UserControl
and the ZoomBoxSlider
are in same window now how can i bind the zoombox
property of the ZoomBoxSlider
with the ZoomBoxPanel
control of the created UserControl
Thanks and regards
Easwar
推荐答案
public class MyUserControl : UserControl
{
...
public ZoomBoxPanel MyZoomBox
{
get { return zoomBox; }
}
...
}
,并将此属性用于绑定:
and, use this property for the binding:
<local:MyUserControl x:Name="myUc" ... />
<zb:ZoomBoxSlider Margin="10" Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Top"
ZoomBox="{Binding ElementName=myUc, Path=MyZoomBox}" />
这篇关于如何在usercontrol中引用控件以进行绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!