How to apply TextTrimming CharacterEllipsis to text in TextBlock - button

I have text block and a button . They are attached in a grid in consecutive colums. There CharacterEllipsis not worked in text block. Code is given below. Please give an idea on how to do this.

The TextTrimming trigger condition is that the length of the current Text exceeds the size of the TextBlock. From that, for TextTrimming to take effect, you can do this in the following two ways:
Set the Width of the TextBlock:
<TextBlock TextTrimming="CharacterEllipsis" Width="100" Text="{x:Bind Name}" .../>
If the width of the TextBlock parent container is fixed and does not need to change with the content size, you can explicitly set TextBlock.Width.
Change container type to Grid:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<!--First column element-->
<TextBlock TextTrimming="CharacterEllipsis" Grid.Column="1" Text="{x:Bind Name}" .../>
</Grid>
Grid and StackPanel are different. Although its width is also related to content, you can limit the width of a column of the Grid to not exceed the parent container by setting <ColumnDefinition Width="1*" />, which also achieves the purpose of setting the width in disguise.
This method is more flexible and suitable for situations where the width of the container is uncertain.
Best regards.

Related

xamarin.forms: image is rendered differently on android than on ios

I am building this view currently:
This is a snapshot of the ios render, the code simply is:
<StackLayout>
<Image Source="img_logo"/>
</StackLayout>
But Android is not quite the same:
I tried everything, giving it verticaloptions, horizontaloptions, changing the aspect to everything, the image is never displayed as it is in ios. It is either clipped, or loses its original aspect ratio. I dont know what else to try here and why I have to do anything in the first place. Please tell me the atributes I need to use...
This code is expected to be rendered differently in some cases.
It is very important what is the target screen density of the image in your platform project. If it is different then obviously it will be rendered at a different size with the code above.
If you want to achieve the same look set the Width or Height property or both. Assuming that the container allows those values (that it is big enough) it will look exactly the same then.
If you want to adjust adjust the size of the image according to the space ratio of different views on the page, you can use Grid to achieve this.
You can set the width to Star or a special value.
For more about this, you can check rows-and-columns.
You can refer to the following code:
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="200" />
</Grid.RowDefinitions>
<!-- Logo -->
<Image Grid.Row="0"
Source="test.png"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
<!-- Sign In Button -->
<StackLayout Grid.Row="1" Padding="10,0,10,0" VerticalOptions="Center">
<Button VerticalOptions="Center" Text="Sign In " />
</StackLayout>
</Grid>
</ContentPage.Content>

Need a way to place a <ScrollView/> over an <Image/> in Xamarin layout XAML

I have the need for a scrollview on top of a background image. I found a number of recommendations to use a , making the image the first element. What I end up with is:
<ContentPage>
<ContentPage.Content>
<RelativeLayout Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
Using the above, I get a screen that looks correct, but the ScrollView doesn't scroll.
Am I missing something? Or does anyone have an alternative to the layout above? The background needs to be fixed and not scroll with the other elements on "top" of it.
It turns out there is a way to do this such that the two main requirements (fixed background, scrollable elements) are met.
Instead of using RelativeLayout, use a Grid. The following layout works as needed...
<ContentPage>
<ContentPage.Content>
<!-- Use a Grid, rather than a RelativeLayout -->
<Grid Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</Grid>
</ContentPage.Content>
</ContentPage>

Xamarin Forms Shell TitleView does not center image

I have an app that uses the new Shell in Xamarin.Forms. I added the following code to one of my pages in an attempt to use the TitleView area to display my app header image centered. (FYI - I have tried Center for both of the alignment options and it made no difference.)
<Shell.TitleView>
<Image Source="UCIApp.png"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
</Shell.TitleView>
What I get after doing this is the image in the title bar but centered in the space the excludes the hamburger button on the left as shown below:
What I would prefer is it centered regardless of the space the hamburger menu takes up looking something like this:
Any suggestions?
ALSO - Putting the image in the TitleView is causing it to be shrunk down. Is there any way to avoid that?
Yes, design fail and there is no option customization. I prefer Grid for like this problems. You can use column or row with percentage.
Default place.
<Shell.TitleView>
<Grid>
<ffimageloadingsvg:SvgCachedImage
Source="https://stackoverflow.design/assets/img/logos/so/logo-stackoverflow.svg"
Margin="10"/>
</Grid>
</Shell.TitleView>
In this example 4/5 unit first column and 1/5 unit second column (* sign presents percentage or divide).
<Shell.TitleView>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="Yellow"/>
<BoxView Grid.Column="1" BackgroundColor="LightGoldenrodYellow"/>
</Grid>
</Shell.TitleView>
Then add image text or control to prefered layout (image control default column is 0).
<Shell.TitleView>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<ffimageloadingsvg:SvgCachedImage
Source="https://stackoverflow.design/assets/img/logos/so/logo-stackoverflow.svg"
Margin="10"/>
</Grid>
</Shell.TitleView>
Edit: Add min height to grid or image control for prevent resize content. Also ffimageloadingsvg is third party package for loading svg files.
I think that's the designed problem about Shell Title View ,you can submit it as a
feature request in GitHub here .
What I would prefer is it centered regardless of the space the hamburger menu takes up looking something like this: ... Any suggestions?
The title view already been placed center in Title View . However , it looks like not center in the whole Navigation Bar . Have a look at follow code and effect .
<Shell.TitleView>
<StackLayout HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
BackgroundColor="Accent">
<Image Source="xamarin_logo.png"
HorizontalOptions="Center"
VerticalOptions="Center" />
</StackLayout>
</Shell.TitleView>
The effect :
You can see that the content of Title View , And the icon already been center in Title View .Because of existing meun icon , the weight of Title View is not equal with Navigation Bar .
Putting the image in the TitleView is causing it to be shrunk down
Refer to above effect , you can see that The size of the icon is adapted to the Title View display, and you can see the size of the Title View, so your icon is unlikely to exceed the display range of the Title View.

How to remove the spacing behind a picker that used to be taken up by a carat?

I would like to remove the carat sign behind a picker in UWP
As such I followed this post -
Xamarin.Forms UWP - How to hide or change color of Picker / ComboBox dropdown arrow - to remove the carat.
Now the carat is removed but the space is still being taken up causing the text to not display correctly (incomplete display):
I tried adjusting the margins but I still get the same bug.
Any idea which part of the code in the link above am I supposed to adjust or if I am missing out some lines of code which could help remove this spacing that the carat used to occupy?
In addition to setting the DropDownGlyph.Visibility to collapsed, you also have to modify the Grid column, in which it is supposed to be to have zero width. You will find the following in the style:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="32" />
</Grid.ColumnDefinitions>
The second column has hardcoded width of 32, which makes the "space" for the arrow to be there even if the arrow is not actually displayed. To remove it, just set the width to 0 or remove the column altogether:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
</Grid.ColumnDefinitions>

How to prevent row stretching vertically in a grid?

I have following code. When there is more than 1 row, it displays the rows with correct height. However, once there is only ONE row left, it's height stretches to the whole grid.
Can anybody tell me how I can get the normal height for the single row? Thanks a lot.
The code:
<ScrollViewer Height="100">
<Grid Name="dataSetGrid2">
<Grid.RowDefinitions></Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
</Grid>
</ScrollViewer>
This may help you figure why it happens like that.
Christian Moser's Blog
The most useful part for you would be the "Define Rows and Columns" section.
Fixed Fixed size of logical units (1/96 inch)
Auto Takes as much space as needed by the contained control
Star (*) Takes as much space as available (after filling all auto and fixed sized columns), proportionally divided over all star-sized columns. So 3*/5* means the same as 30*/50*. Remember that star-sizing does not work if the grid size is calculated based on its content.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
</Grid>

Resources