简体   繁体   中英

How to binding data to and register property in user controls WP8

I have a user controls:

<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>

Title: string ImageSource: BitmapImage

How to use binding data in MainPage.xaml like:

<Grid>
<local:myUserControl Title="{Binding Title"} ImageSoure="{Binding ImageSource}" />
</Grid>

How to do that? Thanks

Sounds like you're basically asking "How do I do binding". A good read is: http://msdn.microsoft.com/en-us/magazine/hh852595.aspx and nearly any other Binding resource you find out there.

In your case you will need an object that has a Title and a ImageSource property that is set as the DataContext of the control (or one of its parents like the PhoneApplicationPage ). You can set the DataContext from your code behind (or in XAML) (if you're on the Page then you can simple set DataContext = ... .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM