【发布时间】:2021-01-14 09:53:03
【问题描述】:
我收到以下错误'System.Reflection.TargetInvocationException: '异常已被调用的目标抛出。'
这是我的代码
ContactModel ConversationPartner;
public MessagesPage(ContactModel input)
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
ConversationsList = new ObservableCollection<ConversationModel>();
ConversationPartner = input;
...
}
...
public string FirstContactName
{
get { return ConversationPartner.contactName[0]; }
}
public string SecondContactId
{
get { return ConversationPartner.contactID[1]; }
}
public string SecondContactName
{
get { return ConversationPartner.contactName[1]; }
}
这是我的 XAML,特别是我尝试绑定 FirstContactName、SecondContactId 和 SecondContactName 的地方
<ContentPage.BindingContext>
<x:Reference Name="messagesPage" />
</ContentPage.BindingContext>
...
<Label Text="{Binding FirstContactName}" FontSize="Title" TextColor="Black"
VerticalOptions="Center" FontAttributes="Bold" HorizontalOptions="StartAndExpand">
<Label.Triggers>
<DataTrigger TargetType="Label" Binding="{Binding SecondContactId, Converter={StaticResource isViewerConverter}}" Value="False">
<Setter Property="Text" Value="{Binding SecondContactName}"/>
</DataTrigger>
</Label.Triggers>
</Label>
【问题讨论】:
-
您在哪里将数据源绑定到内容页面?只是使用
<ContentPage.BindingContext> <x:Reference Name="messagesPage" /> </ContentPage.BindingContext>,请看Data Bindings to mvvm 修改你的binging。
标签: c# xamarin xamarin.forms xamarin.android