1

我是 windows phone 开发的业余爱好者,也是 wpf 的新手。我有一个网格:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" >

                        <Grid HorizontalAlignment="Stretch">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>



                            <TextBlock Text="{Binding StrDay}" 
                                        Grid.Row="0"
                                        Margin="9,-7,0,0" 
                                        Style="{StaticResource PhoneTextTitle1Style}"/>

                            <TextBlock Text="Day's Highlight" 
                                        Grid.Row="1"
                                        FontWeight="Bold"
                                        Style="{StaticResource PhoneTextNormalStyle}"
                                        />

                            <TextBlock Text="{Binding DaysHighlight}"
                                        Grid.Row="2"
                                        Style="{StaticResource PhoneTextNormalStyle}"
                                        />

                            <TextBlock Text="My Whole Day"
                                        Grid.Row="3"
                                        FontWeight="Bold"
                                       Style="{StaticResource PhoneTextNormalStyle}"
                                        />

                            <TextBlock Text="{Binding WholeDay}"
                                        Grid.Row="4"
                                        Style="{StaticResource PhoneTextNormalStyle}"
                                        />
                        </Grid>

我想将它与 DayDetail 对象绑定。我应该提到 DayDetail 不是一个集合。它只是一个具有 StrDay、DaysHighlight、WholeDay 属性的类的对象。我正在关注 MVVM 结构。

public void loadSelectedData(int Id)
        {
            try
            {
                DayDetail = myDiaryData.tblMyDailyDiary.Single(details => details.Id == Id);

            }

            catch (Exception e)
            {
            }

        }
4

1 回答 1

1

我找到了解决方案。

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" DataContext="{Binding DayDetail}" >

只需添加DataContext="{Binding DayDetail}"绑定整个事情。感谢大家的帮助。它对我很好

于 2013-07-16T18:54:36.643 回答