如何在usercontrol中引用控件以进行绑定 [英] How to reffer a control in usercontrol for binding

查看:70
本文介绍了如何在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}" />




上面的代码可以正常工作,因为ZoomBoxPanelZoomBoxSlider都在同一窗口中.

但是如果我在其中放置ZoomBoxPanel的地方创建一个UserControl,现在创建的UserControlZoomBoxSlider在同一个窗口中,现在我该如何将ZoomBoxSliderzoombox属性绑定到创建的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

推荐答案

您可以将保存ZoomBoxPanel的属性添加到UserControl:

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中引用控件以进行绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆