[英]How to binding data to and register property in user controls WP8
我有一个用户控件:
<UserControl>
<Grid Name="grid1" Background="#1133CC" Canvas.ZIndex="1" Width="200" Height="200">
<Image Name="img1" Source="{Binding ImageSource}" />
<TextBlock Text="{Binding Title"}/>
</Grid>
</UserControls>
标题:字符串ImageSource:BitmapImage
如何在MainPage.xaml中使用绑定数据,例如:
<Grid>
<local:myUserControl Title="{Binding Title"} ImageSoure="{Binding ImageSource}" />
</Grid>
怎么做? 谢谢
听起来您基本上是在问“我该怎么做”。 很好的阅读方法是: http : //msdn.microsoft.com/zh-cn/magazine/hh852595.aspx以及您在此处发现的几乎所有其他绑定资源。
在您的情况下,您将需要一个具有Title
和ImageSource
属性的对象,该属性设置为控件的DataContext
(或其父级之一,如PhoneApplicationPage
)。 您可以在代码后面(或在XAML中)从代码中设置DataContext
(如果您位于Page上,则可以简单地设置DataContext = ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.