다음 버튼을 사용하여 여러 레이블을 전달하기 위해 코드를 설정하는 데 도움을 찾고 있습니다. 기본적으로 페이지가 열릴 때 레이블을 설정하고 다음 버튼을 누르고 새 레이블이 현재 레이블을 대체하도록합니다 (새 콘텐츠 페이지를 설정하지 않음). 저는 Xamarin.Forms에서 작업하는 초보자이고 데이터 바인딩 프로세스를 실제로 이해하지 못하고 있습니다. 누군가가 도움이 될 좋은 참조 (Microsoft 웹 사이트 제외)가 있다면. 아래 코드는 아직 아무것도하지 않을 것입니다. 미리 감사드립니다. :)
이것은 ContentPage입니다.
<ContentPage.Content>
<StackLayout>
<Label Text="{Binding TitleText}" />
<ScrollView VerticalOptions="FillAndExpand">
<StackLayout>
<Label Text="{Binding EngText}" />
<Label Text="{Binding ItText}" />
</StackLayout>
</ScrollView>
이것이 내가 코드 뒤에 시작한 것입니다.
'' '' ''
namespace MVVM2
{
public partial class MainPage : ContentPage
{
List<MainPage> Contacts { get; set; }
int ndx = 0;
public string TitleText { get; set; }
public string EngText { get; set; }
public string ItText { get; set; }
public MainPage()
{
InitializeComponent();
Contacts = new List<MainPage>();
// repeat this for as many contacts as you need
Contacts.Add(new MainPage
{
TitleText = "Title1",
EngText = "EngText1",
ItText = "ItText1"
});
Contacts.Add(new MainPage
{
TitleText = "Title2",
EngText = "EngText2",
ItText = "ItText2"
});
Contacts.Add(new MainPage
{
TitleText = "Title3",
EngText = "EngText3",
ItText = "ItText3"
});
// display the first contact
BindingContext = Contacts[ndx];
}
private void OnNavigateButtonClicked(object sender, EventArgs e)
{
// increment your index
ndx++;
// check that we haven't gone too far
if (ndx < Contacts.Count)
{
BindingContext = Contacts[ndx];
}
}
}
}
버튼을 클릭 할 때 다른 텍스트 만 표시하려는 경우 새 페이지로 이동할 필요가 없습니다.
먼저 List
버튼을 유지하기위한를 만들고 어떤 버튼이 표시되는지 추적하는 변수를 만듭니다 . 이 두 줄은 클래스 본문에 있어야하지만 특정 메서드 내부에는 있어야합니다.
List<Contact> contacts { get; set; }
int ndx = 0;
그런 다음 생성자에서 데이터를 설정하십시오.
public MainPage()
{
InitializeComponent();
contacts = new List<Contact>();
// repeat this for as many contacts as you need
contacts.Add(new Contact {
TitleText = "Title1",
EngText = "EngText1",
ItText = "ItText1"});
// display the first contact
BindingContext = contacts[ndx];
}
마지막으로 버튼 클릭 처리
async void OnNavigateButtonClicked(object sender, EventArgs e)
{
// increment your index
ndx++;
// check that we haven't gone too far
if (ndx < contacts.Count) {
BindingContext = contacts[ndx];
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다