Found this for change to change the color of the backbutton .
NavigationPage.SetIconColor(this, Color.FromHex("#FFFF00"));
The backgroudcolor of the page i change with DynamicResource.
Invul.xaml.cs
App.Current.Resources["defaultBackgroundColor"] = Preferences.Get("BackgroundColor", "#1D252D");
For the Backcolor of the backbutton i tryed this but not working because Color.FromHex i think ,can i change the FromHex part in to ?
NavigationPage.SetIconColor(this, Color.FromHex("{DynamicResource defaultBackgroundColor}"));
If you want to use color from ResourceDictionary , you can access it first and pass the result color to the second parameter of method NavigationPage.SetIconColor.
Please refer to the following code:
Color color = (Color)Application.Current.Resources["defaultBackgroundColor"];
NavigationPage.SetIconColor(this, color);
The defaultBackgroundColor is a color in Application.Resources:
<Application.Resources>
<ResourceDictionary>
<!-- Colors -->
<Color x:Key="defaultBackgroundColor">Red</Color>
<Color x:Key="Yellow">#ffd966</Color>
</ResourceDictionary>
</Application.Resources>
Related
I've created a tabbedpage to create a horizontal menu at the bottom of the page, but I can't set the scroll property.
This is my code:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GET_SOUND.Views.MenuPage"
xmlns:local="clr-namespace:GET_SOUND.Views"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.IsSmoothScrollEnabled="True"
BarBackgroundColor="{StaticResource Primary}"
SelectedTabColor="Orange"
UnselectedTabColor="#95FFFFFF">
<!--Pages can be added as references or inline-->
<local:Dashboard Title="Dashboard" Icon="dashboard" />
<local:Marchi Title="Marchi" Icon="marchi" />
<local:Isrc Title="Isrc" Icon="matrici" />
<local:Documenti Title="Documenti" Icon="documenti" />
<local:Documenti Title="Impostazioni" Icon="imp" />
<local:Anagrafica Title="Anagrafica" Icon="anagrafica" />
<local:OpereTutelate Title="Opere Tutelate" Icon="opere" />
I tried to insert -> App: tabmode = "Scrollable" and the assembly, as suggested in this question, but it gives me an error and I don't understand why
As a suggestion, you can try use
Shell Tab,As it says in documents:
When there are more than five tabs on a TabBar, a More tab will
appear, which can be used to access the additional tabs
And Xamarin.Community is also an option, you can set the scrollable tab on the bottom with TabStripPlacement="Bottom".you can see more in https://github.com/xamarin/XamarinCommunityToolkit/blob/main/samples/XCT.Sample/Pages/Views/TabView/ScrollTabsPage.xaml
I am unable to change the status bar text color of my Xamarin Forms iOS app to white. I have change in my info.plist as follow:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Yet the color still remain black.. Is there another way to change the status bar text color?
In Xamarin.Forms, there are three things you need to do to achieve white text in the iOS Status Bar. I've also posted a sample Xamarin.Forms app below that uses white text in the iOS Status Bar.
1. Update the Info.plist
In Info.plist, add the Boolean Property View controller-based status bar appearance and set its value to No
2. Use a NavigationPage & Set the Navigation Bar Text Color to White
In the Application class (typically App.cs), the MainPage must be a NavigationPage, and the BarTextColor must be set to Color.White
3. Clean & Rebuild the App
Sometimes the compiler doesn't update the Status Bar Color until you Clean and Rebuild the app, so after making the changes in steps 1 & 2, clean the app and rebuild it.
Sample App
https://github.com/brminnick/SaveImageToDatabaseSampleApp/
The only way to change status bar in IOS for me was to use this code in FinishedLaunching in AppDelegate
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init ();
LoadApplication (.....);
app.SetStatusBarStyle(UIStatusBarStyle.LightContent, true);
return base.FinishedLaunching (app, options);
}
So what I did for changing status bar color and status bar text color is:
Info.plist
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<!--<key>UIStatusBarHidden</key>-->
<!--<true/>-->
AppDelegate
Inside function FinishedLaunching(), add code below:
UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
if (statusBar != null && statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
{
statusBar.BackgroundColor = Color.FromHex("#7f6550").ToUIColor(); // change to your desired color
}
App.xaml
I added code below to change status bar text color to White.
<Style TargetType="{x:Type NavigationPage}">
<!--<Setter Property="BarBackgroundColor" Value="Black" />-->
<Setter Property="BarTextColor" Value="White" />
</Style>
Select the NavigationBar and change the Style property to Black.
In my case, adding this to AppDelegate FinishedLaunching worked:
UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
Hi i have spend some days searching for the answer how to solve this
This is what i want, just made a image how it should look like
What is the best solution to use to solve this?
I tryed to do this with a Frame but it just allowed be to use 1 content .
Can i use more then one content in some way
( Content can just have one setup of fontcolor and fontsize and so on. )
I just get to this part
Here i try to put a label with margin with - so it go above.
But this is really bad to to. because i need to have the implementation under the frams. like this.
_stack.Children.Add(frame);
_stack.Children.Add(bordertext);
and when i fill the frame with content the lable apear in another position because how it relate to the margin when the Frame get higher.
But if i put the lable implementation above the Frame then it appear in the background of the frame
_stack.Children.Add(bordertext);
_stack.Children.Add(frame);
And the label get weard with the shadow that i cant figure out how to get rid of.
C#
Frame frame = new Frame
{
BorderColor = Color.Brown,
CornerRadius = 10,
HasShadow = false,
Margin = 10,
BackgroundColor = Color.White,
};
Label bordertext = new Label( );
bordertext.Text = "BorderText";
bordertext.Margin = new Thickness(40, -65,0 , 0);
bordertext.BackgroundColor = Color.White;
_stack.Children.Add(frame);
_stack.Children.Add(bordertext);
PART OF THE SOLUTION
#Jason 's solution to put
the Content in a Stacklayout and then put it in a Frame Solves the problem with having more then one text with different font,sizes and stuff.
But i put a text outside the Stacklayout so i can have the Text on the border. But because i put the Bordertext first and then the Frame. Then the Border text gets in the background.
If i put it after the Frame then i gets in the front. But then i have a big problem with dynamic text that the BorderText will appear very strange depending on how much text.
How i cant put the BorderText in front even if i implement in before so i cant move it down a little bit.
_stack.Children.Add(new Label { Text = "Bordertext", Margin = new Thickness(0, 0, 0, -25) });
_stack.Children.Add(_frame);
To compose a layout, first determine what boxes (rectangles) you need inside other boxes. Each "box" is some container (layout) type.
I see one box "A", the size of the parent-container, containing the border lines "B", overlaid by a box "C" that blocks part of one line, and contains a text "D".
I see a second box "E", inset slightly from the parent-container, which contains additional content "F".
To overlay multiple items, use a one-cell Grid, with children at (row,column) of 0,0 - which can be omitted because is default:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FormsApp1.MainPage">
<Grid BackgroundColor="Violet">
<!-- Border lines formed by one box visually "inside" another, via margins.
Instead use "Rectangle" if need rounded corners. -->
<BoxView BackgroundColor="Red" Margin="10"/>
<BoxView BackgroundColor="LightCoral" Margin="16"/>
<!-- Text "box" given size by putting inside a StackLayout. -->
<!-- Some of these dimensions may not be needed. -->
<StackLayout WidthRequest="300" HeightRequest="30">
<Label Text="Header Text" TextColor="Black" BackgroundColor="White" FontSize="18"
HorizontalOptions="Start"
WidthRequest="150" HeightRequest="30" Margin="20,0" Padding="20,0,0,0"/>
</StackLayout>
<!-- this contains your contents. -->
<StackLayout BackgroundColor="#2196F3" Padding="10" Margin="40">
<Label Text="Content line 1" HorizontalTextAlignment="Center" TextColor="White"/>
<Label Text="Content line 2" HorizontalTextAlignment="Center" TextColor="White"/>
</StackLayout>
</Grid>
</ContentPage>
"Positioning" is done via "Margin" and "Padding" properties.
I've used various colors, so you can see the parts of this layout. "ContentPage" wrapper might not be needed; use whatever your app expects as topmost container.
layout of group' frame' with header text:
I have two resource as this:
<Color x:Key="Color1">#17110F</Color>
<Color x:Key="Color2">#FDFDFD</Color>
if i use aso, this work for me
App.Current.Resources["Color1"] = Color.FromHex("#FDFDFD");
but i want use so: that is possible?
Style color = App.Current.Resources["Color1"];
this is possible?
You can do what you want but the value you are getting from the Resources is a Color not a Style. You will also need to cast the value since the returned value comes in the form of an Object.
var color2 = (Color)App.Current.Resources["Color2"];
or
Color color2 = (Color)App.Current.Resources["Color2"];
The above line should give you what you want.
Hope this helps.-
I want to set a background image to my Grid in code behind. I found in internet that we can do using XAML like this.
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Pages.PhotoPage">
<Grid >
<Image Source="background.png" Aspect="AspectFit" />
<!-- Place here the rest of the layout for the page. -->
</Grid >
But how can I set this in code behind. I cannot see anyImage or BackgroundImage property for Grid. Please help me.
Thanks
You can just create an empty Image element in the Grid and set it.
<Grid>
<Image x:Name="BackgroundImage" Aspect="AspectFit" />
<!-- Place here the rest of the layout for the page. -->
</Grid>
And now set it in code:
backgroundImage.Source = ...;
If you are building the whole UI in code, you can do this as well:
var myGrid = new Grid();
var backgroundImage = new Image();
backgroundImage.Source = ...;
myGrid.Children.Add( backgroundImage );
If your Grid has multiple rows and columns, you will want to set the Grid.ColumnSpan and Grid.RowSpan properties on the image to make it span the whole grid.