我是 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)
{
}
}