微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XAML

如何解决XAML

我的 XAML 中有这些代码

    <ContentPage.BindingContext>
        <x:Reference Name="messagesPage" />
    </ContentPage.BindingContext>

    ....

  <Label Text="{Binding ConversationPartner.contactName[0]}" FontSize="Title" TextColor="Black"
                           VerticalOptions="Center" FontAttributes="Bold" HorizontalOptions="StartAndExpand">
                        <Label.Triggers>
                            <DataTrigger targettype="Label" Binding="{Binding ConversationPartner.contactID[1],Converter={StaticResource isViewerConverter}}" Value="False">
                                <Setter Property="Text"  Value="{Binding ConversationPartner.contactName[1]}"/>
                            </DataTrigger>
                        </Label.Triggers>
                    </Label>

我想要发生的是 ConversationPartner.contactName[0] 表示的标签上的名称必须出现在我的应用程序中,但它没有。

这是后面的代码

public partial class MessagesPage : ContentPage
{
        DataClass dataClass = DataClass.GetInstance;
        public ICommand CloseMsg => new Command(async () => await Navigation.PopModalAsync(true));
        public ICommand SendCommand => new Command(Send);
        
        ContactModel ConversationPartner;
        public MessagesPage(ContactModel input)
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this,false);
            ConversationsList = new ObservableCollection<ConversationModel>();
            ConversationPartner = input;
            /// some cloud firestore code here
        }
}

解决方法

找到了解决方案。

我制作了一个可观察的集合,以便我可以轻松地绑定。 我背后的代码:

     public MessagesPage(ContactModel input)
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this,false);
            ConversationsList = new ObservableCollection<ConversationModel>();
            convoers = new ObservableCollection<string> {input.contactName[0],input.contactName[1],input.contactID[1] };
            ConversationPartner = input;
            ...
        }

然后在我的 XAML 中,

 <Label Text="{Binding convoers[0]}" FontSize="Title" TextColor="Black"
                           VerticalOptions="Center" FontAttributes="Bold" HorizontalOptions="StartAndExpand">
                        <Label.Triggers>
                            <DataTrigger TargetType="Label" Binding="{Binding convoers[2],Converter={StaticResource isViewerConverter}}" Value="False">
                                <Setter Property="Text"  Value="{Binding convoers[1]}"/>
                            </DataTrigger>
                        </Label.Triggers>
                    </Label> 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。