die MVVM-Muster verwenden, die Benutzeroberfläche der Anwendung und die zugrunde liegende Präsentation und Geschäftslogik XAML und Code: Textblocks, die wie folgt definiert Bilder:Kann in mvvm nicht an Textblock gebunden werden?
<Page.DataContext>
<ViewModel:TweetVM/>
</Page.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" >
<Image x:Name="Thumbnail" Source="{Binding GetAccount.ProfileImgUrl}" Width="100" Margin="8"/>
<StackPanel Margin="8">
<TextBlock x:Name="UserName" Text="{Binding GetAccount.Name}" Foreground="#262626" VerticalAlignment="Top"/>
<TextBlock x:Name="AccountName" Text="{Binding GetAccount.ScreenName}" Foreground="#666666"/>
</StackPanel>
</StackPanel>
Code: Hier vollständiger Code ist:
public class TweetVM : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private Accounts getAccount;
public Accounts GetAccount {
get { return getAccount; }
set
{
getAccount = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GetAccount"));
}
}
public TweetVM()
{
GetProfile();
}
/// <summary>
///
/// </summary>
public async void GetProfile()
{
try
{
GetAccount = new Accounts();
var profile = await(from index in twtContext.Account
where index.Type == AccountType.VerifyCredentials
select index).SingleOrDefaultAsync();
GetAccount.Name = profile.User.Name;
GetAccount.ProfileImgUrl = profile.User.ProfileImageUrl;
GetAccount.ScreenName = profile.User.ScreenNameResponse;
}
catch (Exception ex)
{
errorDialog = new ErrorDialog(ex.Message, "Error : ");
}
}
GetAccount hat Daten, aber sehen keine Bindung an Textblock, ... Was ist das Problem ?. Ich verstehe nicht, wo das Problem ...
prüfen 'BindingMode' – AnjumSKhan
Ihr Problem ist' async void' Methode. Da die Methode "Task" nicht zurückgegeben hat, können Sie das Ergebnis nicht beobachten. Wenn "GetProfile" -Methode wird Ausnahme auslösen - nichts passiert-was ist offensichtlich in Ihrem Fall hepfened – Fabio
Nein errors.var profile = erwarten (aus dem Index in twtContext.Account .... –