I create an image-button using below code:
ImageBrush btnBrush1 = new ImageBrush();
btnBrush1.Stretch = Stretch.Uniform;
btnBrush1.ImageSource = new BitmapImage(new Uri("ms-appx:/Images/icon_LogIn.png"));
btnLogIn.Background = btnBrush1;
The problem:
1) When using a mouse hovering the img-button, it turn grey background and icon disappear ( when not hovering the img-button, this image button is visible.
I want this image-button visible when hovering it or pressing it.
Thanks
You need to set Image as Content rather than setting ImageBrush as Background.
Try this
Image img=new Image();
img.Source=new BitmapImage(new Uri("/Images/icon_LogIn.jpg",UriKind.RelativeOrAbsolute));
btnLogIn.Content = img;
Related
I would like to have a customized Dialog styling, having another background color and a rounded border, as it looks nicer than the gray rectangle that comes by default.
This is partially possible, by styling the Contentpane of the Dialog. The problem is, that the underlying Dialog Style is still there, in which the contentpane is shown. And it seems the Dialog UDID itself cannot be changed, nor can the "Dialog" style be overwritten in the designer nor by code.
Form hi = new Form();
hi.getUnselectedStyle().setBgColor(0xffffff);
Button but = new Button("open dialog");
but.addActionListener(e -> {
Dialog d = new Dialog(BoxLayout.y());
d.setUIID("Container"); // this line has no effect, the outside dialog component is still visible
Style s = d.getContentPane().getUnselectedStyle();
s.setBorder(RoundRectBorder.create());
s.setBgColor(0x00ff00);
s.setBgTransparency(255);
s.setMargin(5, 5, 5, 5); // adding some margin between contentpane and Dailog container, to be more obvious
d.setDisposeWhenPointerOutOfBounds(true);
// title
Label title = new Label();
title.setText("Confirmation");
d.add(title);
// body field with spanlabel info text
SpanLabel bodyLabel = new SpanLabel("Body Text");
d.add(bodyLabel);
// delete button
Button okButton = new Button("Ok");
okButton.addActionListener(e2 -> {
d.dispose();
});
// exit button
Button exitButton = new Button("Cancel");
exitButton.addActionListener(e3 -> {
d.dispose();
});
d.add(GridLayout.encloseIn(2, okButton, exitButton));
d.show();
});
hi.add(but);
hi.show();
In above image, the outermost dark gray is the tinted area outside the dialog. The green is the content pane with the intended rounded border. the light grey in between comes from the Dialog style that I would like to get rid off.
Can this be done?
Short answer: setDialogUIID("Container");
However dialogs are a bit problematic to customize via code, I would strongly recommend styling them via the designer/css as we just didn't design them for hand styling and so you're relying on internal implementation details that might break.
When you invoke getContentPane() on the Dialog you're styling the content pane of the Dialog. Not the Dialog itself so the dialog styling still has the non-transparent background. You can use getDialogStyle() to style the Dialog itself. I'm not sure how well that will work.
I'm new in xamarin(start using 2 week), now I need do a background Image wtih navigation bar like below picture? how can I do it?
You need to add an UIImage in your UIViewController (filling whole or only top of ViewController) setting your UINavigationBar to a clear color with
YourNavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
YourNavigationBar.ShadowImage = new UIImage();
YourNavigationBar.Translucent = true;
YourNavigationBar.BackgroundColor = UIColor.Clear;
To reset UINavigationBar transparency you have to use:
YourNavigationBar.SetBackgroundImage(null, UIBarMetrics.Default);
Good day all,
I have a simple Dialog started after click button, I post my code:
Dialog dialog;
super();
dialog = new Dialog("Dialog example");
dialog.addText(strFmt("Text to show"));
dialog.addText(strfmt("SecondText to show"));
dialog.run();
I will show a Dialog window loollike this :
It's possible to set the position from code the Text: Text to show ?
For example, if I want to centered position the second text how should I do?
I tried to put blanks in the code:
dialog.addText(strfmt(" Text to show"));
But nothing changes, and this I think not good method.
I saw any suggestions on Web but or I do not use well or is not suitable for me: Example-suggestions.
Exist a method to do what I want?
Thanks for help,
enjoy!
You can center the text using the form control:
Dialog dialog = new Dialog("Dialog example");
DialogText t1 = dialog.addText(strFmt("Text to show"));
DialogText t2 = dialog.addText(strfmt("SecondText to show"));
FormStaticTextControl c1 = t1.control();
c1.widthMode(FormWidth::ColumnWidth);
c1.alignment(FormAlignment::Center);
dialog.run();
The first control is now centered (to the surrounding group).
You have to give it ColumnWidth, otherwise the control would have the minimum size and the centering would have no effect.
Below is my code I used to create a custom UITextField in code behind.
UITextField usernameField;
usernameField = new UITextField
{
Placeholder = "Enter your username",
BorderStyle = UITextBorderStyle.RoundedRect,
Frame = new RectangleF(10, 32, 50, 30)
};
View.AddSubview(usernameField);
But when I run my app, I dont see this anywhere. Not only this control but all the controls that I create in code behind.
If I drag the controls from toolbox onto my View it's working very fine.
What might be the cause?
Make sure that Container View is not transparent so Alpha = 1 and set background colors for appropriate controlls. Because by default its set to ClearYou can use this method to easly set background and rounded corners like in older versions of iOS
public static void MakeViewRounded(UIView view,float cornerRadius, MonoTouch.CoreGraphics.CGColor backgroundColor)
{
view.Layer.CornerRadius = cornerRadius;
view.Layer.BackgroundColor = backgroundColor;
}
Also make sure that you adding your custom controll to ViewController/View
I have prepared a screen in which I am allowing user to create an account. as shown in the first image I have used an image(bg_BB.png image) as MainScreen Background, after that i have taken another VFM and painting that white Background (white_bg2.png)on that vertical field manager and ADDING ALL MY FIELD ON THAT VFM.
But the problem arises when the keyboard is pops-up. All the fields apears to be floating over the background as shown in the second pic.
Below is the code which I am using:
Bitmap backGroundImage = Bitmap.getBitmapResource("bg_BB.png");
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createBitmapBackground(backGroundImage));
final Bitmap tabBackGroundImage = Bitmap.getBitmapResource("white_bg2.png");
_mainVfm = new VerticalFieldManager(Field.USE_ALL_WIDTH) {
protected void paint(Graphics graphics) {
int y = CreateUserAccountScreen.this.getMainManager().getVerticalScroll();
graphics.drawBitmap(0, y,
tabBackGroundImage.getWidth(),
tabBackGroundImage.getHeight(),
tabBackGroundImage,
0, 0 );
super.paint( graphics );
}
};
replace your code with:
Bitmap tabBackGroundImage = Bitmap.getBitmapResource("white_bg2.png");
VerticalFieldManager _mainVfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL |
Manager.VERTICAL_SCROLLBAR|
Manager.USE_ALL_WIDTH);
_mainVfm.setBorder( BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), tabBackGroundImage
)
);
make sure that your border image have white background.
i use this method and it works perfectly.