I want to set one color for Grid in .cs. Can you help me?
Try this code:
myGrid.Background = new SolidColorBrush(Color.FromArgb(255, 100, 100, 100));
EDIT:
It doesn't have to be a SolidColorBrush, it can be any class derived from Brush, such as LinearGradientBrush, RadialGradientBrush etc.
you can set like this:
public MainPage()
{
InitializeComponent();
ContentPanel.Background = new SolidColorBrush(Colors.Blue);
}
or
public MainPage()
{
InitializeComponent();
ContentPanel.Background = new SolidColorBrush(Color.FromArgb(value of A, value of R, value of G, value of B));
}
Related
If I switch between my different tabs, I allways get this little click animation that looks like a shadow or sth.
I use a custom Renderer for my Shell, but how can I disable this animation?
Here is a picture of the click animation
I found the solution by myself. Here is my code:
public void ResetAppearance(BottomNavigationView bottomView)
{
}
public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
Android.Graphics.Color elevationBGColor = ((Color)Xamarin.Forms.Application.Current.Resources["ElevationBGColor"]).ToAndroid();
bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityUnlabeled;
bottomView.SetBackgroundColor(elevationBGColor);
int[][] Tintstates = new int[][]
{
new int[] {-Android.Resource.Attribute.StateChecked}, // unchecked
new int[] { Android.Resource.Attribute.StateChecked} // pressed
};
int[] Tintcolors = new int[]
{
Xamarin.Forms.Color.White.ToAndroid(),
((Color)Xamarin.Forms.Application.Current.Resources["PrimaryColor"]).ToAndroid()
};
ColorStateList TintList = new ColorStateList(Tintstates, Tintcolors)
bottomView.ItemIconTintList = TintList;
bottomView.ItemRippleColor = null;
}
In this code I also set a color change to the item i selected in my navbar, but the code i was searching for was
bottomView.ItemRippleColor = null;
I new a grid object without any settings in the xaml file.
After importing the data through 'Build_Grid()' in the 'OnAppearing()', I want to assign the 'gridview' to 'Grid_Info' to display on the screen, the code 'Grid_Info = gridview' does not work.
I am wondering how to achieve my needs?
<ContentPage.Content>
<StackLayout>
<Label Text="AAA" />
<Grid x:Name="Grid_Info">
</Grid>
</StackLayout>
</ContentPage.Content>
void Build_Grid(Data data)
{
Grid gridview = new Grid();
gridview.RowDefinitions.Add(new RowDefinition() { Height = 40 });
gridview.Children.Add(data[0],0,0);
...
Grid_Info = gridview; //it does not work...
}
protected override void OnAppearing()
{
Data data = new Data();
...
Build_Grid(data);
}
if you've already defined the Grid in XAML there is no need to do this
Grid gridview = new Grid();
instead just reference Grid_Info directly
Grid_Info.RowDefinitions.Add(new RowDefinition() { Height = 40 });
Grid_Info.Children.Add(data[0],0,0);
You could try the code below. I make a Data class with view to test. It work for me.
public partial class Page3 : ContentPage
{
Data[] data;
public Page3()
{
InitializeComponent();
data = new Data[2];
data[0] = new Data { view = new Button() { BackgroundColor = Color.Red } }; //data[0]
data[1] = new Data { view = new Label() { BackgroundColor = Color.Green, Text = "Label" } };//data[1]
}
void Build_Grid(Data[] data)
{
Grid gridview = new Grid();
Grid_Info.RowDefinitions.Add(new RowDefinition() { Height = 40 });
Grid_Info.Children.Add(data[0].view, 0, 0);//show the red button
Grid_Info = gridview; //it does not work...
}
protected override void OnAppearing()
{
base.OnAppearing();
Build_Grid(data);
}
}
public class Data
{
public View view { get; set; }
}
I'm developing an IOS Application using Xamarin.Forms and in that I've customized the toolbar color to Gradient color using custom renderers.But,After this the Icons
color is changed as per the toolbar color and how to set the title text to white colour.Here is the renderer I'm using for toolbar customization
public class NavigationPageGradientHeaderRenderer:NavigationRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var control = (NavigationPageGradientHeader)this.Element;
var gradientLayer = new CAGradientLayer();
gradientLayer.Bounds = NavigationBar.Bounds;
gradientLayer.Colors = new CGColor[] { control.RightColor.ToCGColor(), control.LeftColor.ToCGColor() };
gradientLayer.StartPoint = new CGPoint(0.0, 0.5);
gradientLayer.EndPoint = new CGPoint(1.0, 0.5);
UIGraphics.BeginImageContext(gradientLayer.Bounds.Size);
gradientLayer.RenderInContext(UIGraphics.GetCurrentContext());
UIImage image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
NavigationBar.SetBackgroundImage(image, UIBarMetrics.Default);
}
}
After applying this the Icons look like this:
enter image description here
But I want the images background to be transparent like this:
enter image description here
and the title textcolor should be white.
How can I achieve this.Can anyone please help me with this.
Thank you
You can set the property in CustomRenderer
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var control = (MyNativePage)Element;
var gradientLayer = new CAGradientLayer();
gradientLayer.Bounds = NavigationBar.Bounds;
gradientLayer.Colors = new CGColor[] { UIColor.Red.CGColor,UIColor.White.CGColor };
gradientLayer.StartPoint = new CGPoint(0.0, 0.5);
gradientLayer.EndPoint = new CGPoint(1.0, 0.5);
UIGraphics.BeginImageContext(gradientLayer.Bounds.Size);
gradientLayer.RenderInContext(UIGraphics.GetCurrentContext());
UIImage image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
NavigationBar.SetBackgroundImage(image, UIBarMetrics.Default);
NavigationBar.TintColor = UIColor.White;
NavigationBar.TitleTextAttributes = new UIStringAttributes() { ForegroundColor =UIColor.White};
}
If you create an NavigationPage, then you can use like this
var myHomePage = new NavigationPage(dashboardPage){
Tint = Color.Red // put your color here };
You can set common color from App.xaml.cs;
public App()
{
InitializeComponent();
// MainPage = new MainPage();
MainPage = new RESTAPICallApp.Controllers.HomePage();
NavigationPage navigationRootPage = new NavigationPage(new RESTAPICallApp.Controllers.HomePage());
navigationRootPage.BarBackgroundColor = Color.LightSeaGreen;
navigationRootPage.BarTextColor = Color.Wheat;
MainPage = navigationRootPage;
}
For native Xamarin.iOS add this code in 'didFinishLaunchingWithOptions' method on AppDelegate.cs;
UINavigationBar.Appearance.Translucent = false;
UINavigationBar.appearance().barTintColor = UIColor.White
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes() {
TextColor = UIColor.White,
TextShadowColor = UIColor.Clear
});
Is there a way in JavaFX to make a class that extends Group and limit it to accepting only Shape objects as children?
Consider creating a wrapper class instead of a subclass. Something along the lines of
public class ShapeGroup {
private final Group group = new Group() ;
public void addShape(Shape s) {
group.getChildren().add(s);
}
public void removeShape(Shape s) {
group.getChildren().remove(s);
}
// other methods you want to expose, implemented similarly...
public Parent asParent() {
return group ;
}
}
And now you can use this as follows:
ShapeGroup shapeGroup = new ShapeGroup();
shapeGroup.addShape(new Circle(50, 50, 20));
shapeGroup.addShape(new Rectangle(20, 20, 30, 30));
// ...
Scene scene = new Scene(shapeGroup.asParent());
// etc..
My apologies as this is simplistic enough I know the question's been answered but in 30 or so pages, I've yet to find the boiled down problem I'm trying to solve.
I'm not yet well practiced in SL and trying a simple version of attempting to write a TextBox that binds to a property within the screen and updates it when Text is altered and vice versa (property change propagates to the Text). Due to a few reasons, I need to do this with DependencyProperties and in the codebehind rather than INotifyPropertyChanged and in XAML.
My latest attempts look something like this:
public partial class MainPage : UserControl
{
static MainPage()
{
TargetTextProperty = DependencyProperty.Register("TargetText", typeof(string), typeof(MainPage), new PropertyMetadata(new PropertyChangedCallback(TextChanged)));
}
public readonly static DependencyProperty TargetTextProperty;
public string TargetText
{
get { return (string)GetValue(TargetTextProperty); }
set { SetValue(TargetTextProperty, value); }
}
public MainPage()
{
InitializeComponent();
TargetText = "testing";
textBox1.DataContext = TargetText;
Binding ResetBinding = new Binding("TargetText");
ResetBinding.Mode = BindingMode.TwoWay;
ResetBinding.Source = TargetText;
textBox1.SetBinding(TextBox.TextProperty, ResetBinding);
}
private static void TextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
MainPage pg = (MainPage)sender;
pg.textBox1.Text = e.NewValue as string;
}
}
Anyone see what (painfully obvious thing?) I'm missing?
Thanks,
John
The following should be enough to set the binding you want:
textBox1.SetBinding(TextBox.TextProperty, new Binding() { Path = "TargetText", Source = this });
The problem with your code is that you set both Source and binding Path to the TargetText property and as a result you get the framework trying to bind to TargetText.TargetText, which is obviously wrong.