2017-12-31 128 views
2

형식이 지정된 문자열이 있습니다. 코드에서는이보다 더 그러나 이것은 단지 예입니다Xamarin.Forms와 함께 .alert에 FormattedText를 포함시킬 수있는 방법이 있습니까?

var fs = new FormattedString(); 
fs = fs.Spans.Add(new Span { Text = "ABC, ForegroundColor = Color.FromHex("555555") }); 

내가 경고에 서식있는 텍스트를 사용할 수있는 방법이 있나요?

var answer = await DisplayAlert ("Test", alertText, "Yes", "No"); 

답변

3

나는 대답이 "아니오"라고 생각합니다. 나는 어떤 타사 플러그인없이 자주 이렇게 Rg.Plugins.Popup

// Use these methods in PopupNavigation globally or Navigation in your pages 

// Open new PopupPage 
Task PushAsync(PopupPage page, bool animate = true) // Navigation.PushPopupAsync 

// Hide last PopupPage 
Task PopAsync(bool animate = true) // Navigation.PopPopupAsync 

// Hide all PopupPage with animations 
Task PopAllAsync(bool animate = true) // Navigation.PopAllPopupAsync 

// Remove one popup page in stack 
Task RemovePageAsync(PopupPage page, bool animate = true) // Navigation.RemovePopupPageAsync 
<?xml version="1.0" encoding="utf-8" ?> 
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup" 
      xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup" 
      x:Class="Demo.Pages.MyPopupPage"> 
    <!--Animations use example--> 
    <pages:PopupPage.Animation> 
    <animations:ScaleAnimation 
     PositionIn="Center" 
     PositionOut="Center" 
     ScaleIn="1.2" 
     ScaleOut="0.8" 
     DurationIn="400" 
     DurationOut="300" 
     EasingIn="SinOut" 
     EasingOut="SinIn" 
     HasBackgroundAnimation="True"/> 
    </pages:PopupPage.Animation> 
    <!-- Content --> 
</pages:PopupPage> 
public partial class MyPopupPage : PopupPage 
    { 
     public MyPopupPage() 
     { 
      InitializeComponent(); 
     } 

     protected override void OnAppearing() 
     { 
      base.OnAppearing(); 
     } 

     protected override void OnDisappearing() 
     { 
      base.OnDisappearing(); 
     } 

     // Method for animation child in PopupPage 
     // Invoced after custom animation end 
     protected override Task OnAppearingAnimationEnd() 
     { 
      return Content.FadeTo(0.5); 
     } 

     // Method for animation child in PopupPage 
     // Invoked before custom animation begin 
     protected override Task OnDisappearingAnimationBegin() 
     { 
      return Content.FadeTo(1); 
     } 

     protected override bool OnBackButtonPressed() 
     { 
      // Prevent hide popup 
      //return base.OnBackButtonPressed(); 
      return true; 
     } 

     // Invoced when background is clicked 
     protected override bool OnBackgroundClicked() 
     { 
      // Return default value - CloseWhenBackgroundIsClicked 
      return base.OnBackgroundClicked(); 
     } 
    } 

    // Main Page 

    public partial class MainPage : ContentPage 
    { 
     public MainPage() 
     { 
      InitializeComponent(); 
     } 

     // Button Click 
     private async void OnOpenPupup(object sender, EventArgs e) 
     { 
      var page = new MyPopupPage(); 

      await Navigation.PushPopupAsync(page); 
      // or 
      await PopupNavigation.PushAsync(page); 
     } 
    } 
1

같은 몇 가지 패키지를 사용하여 자신의 "popupAlert"를 생성하는 것이 좋습니다. 그것은 말하자면 말하자면 "경고"가 아니며, 기술적으로 나는 새로운 탐색 뷰를 스택에 띄우고 있습니다. 그것은 당신의 요구에 잘 어울릴 수 있습니다.

public class FormHelpers 
{ 
public static async Task FormattedPoppup(INavigation navigation, string message) 
     { 
      var lblTitle = new Label { Text = "Alert", HorizontalOptions = LayoutOptions.Center, FontAttributes = FontAttributes.Bold }; 
      var lblMessage = new Label { Text = message }; 

      var btnOk = new Button 
      { 
       Text = "Ok", 
       WidthRequest = 100, 
       BackgroundColor = Color.FromRgb(0.8, 0.8, 0.8), 
      }; 
      btnOk.Clicked += async (s, e) => 
      { 
       // close page 
       await navigation.PopModalAsync(); 
      }; 

      var layout = new StackLayout 
      { 
       Padding = new Thickness(0, 40, 0, 0), 
       VerticalOptions = LayoutOptions.StartAndExpand, 
       HorizontalOptions = LayoutOptions.CenterAndExpand, 
       Orientation = StackOrientation.Vertical, 
       Children = { lblTitle, lblMessage, btnOk }, 
      }; 

      var page = new ContentPage(); 
      page.Content = layout; 
      await navigation.PushModalAsync(page); 
     } 
    } 

예 :

내가 확인하지 않고 함께/다양한 팝업을 처리하는 내 PCL 프로젝트의 FormHelpers 클래스가/여기에 만들 수 내 일반적인 형식의 경고 팝업 등등 버튼과 서식있는 텍스트 취소 나는이 글에서이 아이디어를 가지고

private async void button_Test_Clicked(object sender, EventArgs e) 
{ 
    await FormHelpers.FormattedPoppup(this.Navigation, "Some alert displayed here"); 
} 

, 다른 목적을 위해 여러 가지 버전/변경이 : 버튼에서 호출하면 폼보기를 클릭

https://forums.xamarin.com/discussion/35838/how-to-do-a-simple-inputbox-dialog