首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

Button.ContentTemplate里的数据没法绑定

2013-08-04 
Button.ContentTemplate里的数据无法绑定?我的问题和http://stackoverflow.com/questions/6125178/data-do

Button.ContentTemplate里的数据无法绑定?
我的问题和http://stackoverflow.com/questions/6125178/data-doesnt-show-on-text-binding很类似,下面是代码:


<phone:PhoneApplicationPage 
x:Class="RPG_Assistent.Pages.DamageTrackerPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <!--<Button Content="Damage" Height="72" HorizontalAlignment="Left" Margin="0,618,0,0" Name="btnDamage" VerticalAlignment="Top" Width="160" Click="btnDamage_Click" />
        <TextBox Height="72" HorizontalAlignment="Left" Margin="158,618,0,0" Name="txtDamage" Text="" VerticalAlignment="Top" Width="286" KeyUp="NumericOnlyTextBox_KeyUp"></TextBox>-->
        <ListBox ItemsSource="{Binding creatureList}" Height="500" HorizontalAlignment="Center" Margin="6,6,0,0" Name="listBox1" VerticalAlignment="Top" Width="400">


            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Button Width="400" Height="120" >
                        <Button.ContentTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Height="80" Width="200">
                                    <StackPanel Orientation="Vertical" Height="40">
                                        <TextBlock Width="100" FontSize="22" Text="Name:" Height="40"/>
                                        <TextBlock Width="100" Text="{Binding Name}" Height="40"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Vertical" Height="40">
                                        <TextBlock Width="100" FontSize="22" Text="Hitpoints:" Height="40"/>
                                        <TextBlock Width="100" Text="{Binding HitPoints}" Height="40"/>


                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </Button.ContentTemplate>
                    </Button>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Grid>

<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
            <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->



Button.ContentTemplate里面的数据绑定不了,stackoverflow到最后似乎也没答案
------解决方案--------------------



<Button Width="400" Height="120" >
                        <Button.Content>
                                <StackPanel Orientation="Horizontal" Height="80" Width="200">
                                    <StackPanel Orientation="Vertical" Height="40">
                                        <TextBlock Width="100" FontSize="22" Text="Name:" Height="40"/>
                                        <TextBlock Width="100" Text="{Binding Name}" Height="40"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Vertical" Height="40">
                                        <TextBlock Width="100" FontSize="22" Text="Hitpoints:" Height="40"/>
                                        <TextBlock Width="100" Text="{Binding HitPoints}" Height="40"/>
                                    </StackPanel>
                                </StackPanel>


                        </Button.Content>
                    </Button>

热点排行