'optional split string ascii char

Is there a ascii char (non printable) to suggest where to split a string when needed. This in order to show in a cell correctly, even when the screen is rotated. I use buttons in a 5x2 grid in this example.

verticalhorizontal

So, "powerslave" change to "power slave" when the text is wrapped to fit into the cell incase the screen is vertical.

eg. "stalingrad" does not fit into a cell, so I would like the have "staling grad" when the screen is vertical.

I want to use it for a xamarin android app. Now xamarin (4.8) makes "stalingra d" or "powerslav e". I do not have any control because there is no wrapping feedback.



Solution 1:[1]

Yes,you can change the data source of above CollectionView based on the orientation of the device Orientation.

First,for how to detect the orientation of the device, you can override method OnSizeAllocated in your page.

    protected override void OnSizeAllocated(double width, double height)
    {
        base.OnSizeAllocated(width, height);

        if (Height > Width)
        {
            viewModel.LoadPortraitData();
        }
        else {
            viewModel.LoadLandscapeData();
        }
    }

For more, check Device Orientation.

Second ,according to your need, we can use CollectionView to display the string list. And we can display its items in a vertical grid by setting its ItemsLayout property to VerticalGrid.

  <CollectionView ItemsLayout="VerticalGrid, 2"  
                    ItemsSource="{Binding items}">

I have made a simple demo,you can refer to the following code:

<StackLayout Margin="20">
    <CollectionView ItemsLayout="VerticalGrid, 2"  
                    ItemsSource="{Binding items}">
    
    </CollectionView>
</StackLayout>

The code of VerticalGridTextPage.xaml.cs:

public partial class VerticalGridTextPage : ContentPage
{

    MyViewModel viewModel;

    public VerticalGridTextPage()
    {
        InitializeComponent();

        viewModel = new MyViewModel();
        this.BindingContext = viewModel;
    }

    protected override void OnSizeAllocated(double width, double height)
    {
        base.OnSizeAllocated(width, height);

        if (Height > Width)
        {
            viewModel.LoadPortraitData();
        }
        else {
            viewModel.LoadLandscapeData();
        }
    }
}

MyViewModel.cs

public class MyViewModel
{
    public ObservableCollection<string> items { get; set; } = new ObservableCollection<string>();


    public void LoadLandscapeData()
    {
        items.Clear();

        items.Add("power  slave");
        items.Add("staling   grad");
    }

    public void LoadPortraitData() {
        items.Clear();
        items.Add("powerslave");
        items.Add("stalinggrad");
    }

    public MyViewModel() {
        LoadPortraitData();
    }
}

For more, check: Vertical grid.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jessie Zhang -MSFT