Windows Phone 7 XAML--获取绑定以使用我的对象的容器

Windows Phone 7 XAML--获取绑定以使用我的对象的容器,xaml,windows-phone-7,binding,relativesource,Xaml,Windows Phone 7,Binding,Relativesource,我要做的是将TextBlock的文本绑定到UserControl的自定义按钮Symbol属性 下面是UserControl的XAML。需要填写TextBlock的绑定部分 <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http:/

我要做的是将TextBlock的文本绑定到UserControl的自定义按钮Symbol属性

下面是UserControl的XAML。需要填写TextBlock的绑定部分

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="Calculator.CalculatorButton"
    d:DesignWidth="120" d:DesignHeight="80">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Image Source="buttonb@2x.png" Stretch="Fill"/>
        <Button x:Name="InvisibleButton" Content="{Binding ButtonSymbol}" Margin="0,0,0,0" d:LayoutOverrides="Width, Height" BorderThickness="1" Click="InvisibleButton_Click"/>
    <TextBlock HorizontalAlignment="Center" Margin="0,0,0,0" TextWrapping="Wrap" 
               Text="{Binding ????????}" 
               VerticalAlignment="Top"/>
    </Grid>
</UserControl>

请注意,这是带有Silverlight的WP7,与其他版本不同。

您需要设置用户控件的DataContext

如果您添加以下内容:

this.DataContext = this;
在用户控件的构造函数或已加载事件中,可以执行以下操作:

Text="{Binding ButtonSymbol}"
注意,您还可以声明性地绑定XAML的数据源,这只是一种简单的编程方式

Text="{Binding ButtonSymbol}"