[英]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.