動作していない次のxamlがあります。
...
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="OrganisationTemplate">
<Grid Margin="40,0,0,0">
<StackPanel>
<TextBlock Text="{Binding name}"></TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
<DataTemplate x:Key="UserStatusTemplate">
<Grid Margin="40,0,0,0">
<StackPanel>
<TextBlock Text="{Binding Path=profile.name}"></TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
...
<!--Panorama item one-->
<phone:PanoramaItem Header="Home">
<ListBox Name="UserStatus" ItemTemplate="{StaticResource UserStatusTemplate}" ItemsSource="{Binding UserStatus}" Margin="0,0,0,96" IsSynchronizedWithCurrentItem="False"/>
</phone:PanoramaItem>
私は次のビューモデルを持っています:
public class Sections
{
public IEnumerable<Organisation> Organisations { get; set; }
public User User { get; set; }
public UserStatus UserStatus { get; set; }
}
class DashboardViewModel : INotifyPropertyChanged
{
public Sections sections = new Sections();
private OrganisationRepository organisationRepository { get; set; }
private UserRepository userRepository { get; set; }
public DashboardViewModel()
{
LoadOrganisationSection();
LoadHomeSection();
}
...
private async void LoadHomeSection()
{
userRepository = new UserRepository();
sections.UserStatus = await userRepository.GetStatus();
UserStatus = null;
}
#region properties
public UserStatus UserStatus
{
get
{
return sections.UserStatus;
}
set
{
if (sections.UserStatus != value)
{
//LoginCredentials.Username = value;
OnPropertyChanged();
}
}
}
...
#endregion
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler tempEvent = PropertyChanged;
if (tempEvent != null)
{
// property changed
tempEvent(this, new PropertyChangedEventArgs(propertyName));
}
}
}
LoadHomeSection内では、section.UserStatusにはルート: section.UserStatus.profile.nameで埋められたプロパティがあります (私はデバッグしたので、そこに明確に存在します) 。明らかに、これはビューモデルに公開されているプロパティに反映されます: UserStatus.profile.name
xaml のサブ プロパティにアクセスするにはどうすればよいですか?
アクセスするプロパティがすぐそこにある場合に機能する他のプロパティがあります(OrganizationTemplateを参照)
他の投稿を見たことがありますが、それらのバージョンを動作させることができません。