In radio button control how to achieve Text before radio circle? - xamarin

What I have
I want to achieve something like this:
This is the reference link that I have used to create radio button existing control: https://github.com/kirtisagar/XamarinFormsRadioButtonXAML
.Xaml Page:
<radio:BindableRadioGroup
Spacing="10"
x:Name="DeviceConditionRadio"
ItemsSource="{Binding DeviceConditionList}"/>
.CS page:
here I have added Item source of radio:
DeviceConditionList is a List<string>()
DeviceConditionList.Add("This device works well");
DeviceConditionList.Add("This device is not working properly");
How to get this kind of design?
Any help regarding this appreciated.!
Thanks.

from the shared link, the default style is Title right and Image left.And the project is based on Custom renderer to do that. You can find the renderer here.
so you can modify this style by renderer.In the shared project not custom RadioButton
in Android and Button in IOS.Then you need custom in each of them.
Android :you can modify xml to exchange the title and image of RadioButton like this:
<RadioButton
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="#null"//set null
android:checked="true"
android:drawableRight="#android:drawable/btn_radio"//reset the image
android:paddingLeft="10dp"
android:text="RadioButton" />
android:button="#null":This statement hides the original system's RadioButton icon.
android:drawableRight="#android:drawable/btn_radio":Add a btn_radio icon that comes with the system to the right of the original icon. I think the RadioButton is packaged on the btn_radio icon.
IOS:Just extend Uibutton to custom button,and modify like this:
CGFloat imageWidth = jumpBtn.imageView.bounds.size.width;
CGFloat labelWidth = jumpBtn.titleLabel.bounds.size.width;
jumpBtn.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);
jumpBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth);
The titleEdgeInsets property and the imageEdgeInsets property are only used to adjust the image and label position properties when the button is drawn, and do not affect the size of the button itself.
If the image is to the right and the label is to the left, the left side of the image is shifted to the right of the labelWidth from the left side of the button, and the right side of the image is moved to the right by the labelWidth from the left side of the label.

Related

Xamarin Forms Add Custom Toolbar at bottom

I have a page created using Xamarin Forms. I want to add a toolbar at the bottom of the screen like an overlay but doesnt change the actual layout of the screen. It should just overlay above everything and always be at the bottom.
It should showup only when there is a particular event. SO it will be added dynamically.
Any ideas - or if you can send point me in the right direction. I do not want to use any nuget packages.
Have you tried to use AbsoluteLayout/Grid?
<Grid>
<StackLayout><Label Text="Your content"/></StackLayout>
<Button x:Name="toolbar" VerticalOptions="End" Text="Your toolbar" />
</Grid>
Show/hide the control based on your event.
If you could show the code of displayToolbar it would be easier to write a code that suits your needs, but it should be pretty easy even without the code :)
You could do this with a RelativeLayout, AbsoluteLayout or a Grid but I recommend doing it with a Grid because is much lighter than RelativeLayout and has a lot more functions than AbsoluteLayout.
So, make the root of every page that you want to use displayToolbar a Grid with one row and one column. Add the actual content of the page to that Grid as a child view.
Now comes the part that would be easier with your code. When you want to display the toolbar, add the toolbar view as a child of the root Grid with VerticalOptions set to LayoutOptions.End.
That's it. The toolbar will be added in front of every view of the page and if you want to dynamically remove the toolbar, remove the root Grid's last child.
The layout would be something like this:
Grid root;
internal SomePageConstructor()
{
root = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
},
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
}
};
root.Children.Add(actualPageContent, 0, 0);
Content = root;
}
void DisplayToolbar()
{
var toolbar = new StackLayout { VerticalOptions = LayoutOptions.End };
root.Children.Add(toolbar, 0, 0);
}
void RemoveToolbar()
{
root.Children.Remove(root.Children[1]);
}
Note: I did this directly on StackOverflow, code could need some corrections.
From this sample, you could do an animation of the toolbar coming from below the page or something like it. Just change the DisplayToolbar and the RemoveToolvar methods.
Obs. Method names on C# are PascalCased (every word is capitalized) so your displayToolbar is DisplayToolbar.
Hope it helps! :)

How to position a view right above the keyboard?

I'm writing a Forms app. How to position a view right at the bottom of the screen and when some entry is focused and the keyboard is visible, the view to be right above the keyboard? On android, it is possible to set Window.SetSoftInputMode(SoftInput.AdjustResize) and that will make the Content resize every time the keyboard is appearing/disappearing. However, I need the status bar to be transparent and SoftInput.AdjustResize doesn't work with WindowManagerFlags.TranslucentStatus. My question is, how do I position a view right above the keyboard without setting SoftInput.AdjustResize?
Take this example:
public Page1()
{
InitializeComponent();
var al = new StackLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
var button = new BoxView {Color = Color.Red, VerticalOptions = LayoutOptions.EndAndExpand};
var entry = new Entry {HorizontalOptions = LayoutOptions.Fill};
al.Children.Add(entry);
al.Children.Add(button);
Content = al;
Content.SizeChanged += (sender, args) =>
{
button.Layout(new Rectangle(0, Content.Height - 120, App.Dimensions.Width, 120));
};
}
If you run this code, when you'll press the input, nothing will change, the "button" will remain on the bottom of the screen not visible because of the overlaying keyboard.
If we add Window.SetSoftInputMode(SoftInput.AdjustResize) in MainActivity's onCreate it works fine, the box is moved above the keyboard on entry's focus.
Also, if we change Content = al; to Content = new ScrollView {Content = al};, it works fine.
However, if we add Window.AddFlags(WindowManagerFlags.TranslucentStatus); in MainActivity's onCreate, none of those methods work anymore.
Thanks in advance.
I'm writing a Forms app. How to position a view right at the bottom of
the screen and when some entry is focused and the keyboard is visible,
the view to be right above the keyboard?
If you are using Xamarin Forms, then wrapping your UI elements in a ScrollView should do the trick. Something like this if you are using XAML:
<ScrollView>
<ScrollView.Content>
// Your Original XAML content here
</ScrollView.Content>
<ScrollView
EDIT:
Looking at the example you just added, I THINK I know what is happening. So, the ScrollView Trick only works for elements that require keyboard input. I.e if you instead had an entry element at the bottom of the screen, and wrapped everything in a ScrollView like I suggested, then the keyboard should push the entry element up for you. However in your case you have a boxview at the bottom of the screen, which the keyboard simply runs over.
What you have for Content.SizedChanged is a good idea, however I don't think the size of the view actually changes when the keyboard pops up (at least, Content.SizeChanged isn't called when the keyboard pops up), so that part of your code is really only called on loading of the page from the MCVE you provided.
HOWEVER, I was able to move the 'button' up when the keyboard appears by doing this:
Replace
Content.SizeChanged += (sender, args) =>
{
button.Layout(new Rectangle(0, Content.Height - 120, App.Dimensions.Width, 120));
};
With
entry.Focused += (sender, e) =>
{
button.TranslationY -= 120;
};
You may have a heck of a time getting that magic translation number for all the different devices and orientations though. When I tested it on the iPhone 6 simulator I had to push way above 120 before I could see it above the keyboard.
Hope that helps!

How to set a background image to an entry cell in xamarin.forms

I have used custom rendering to display the entry cell in xamarin forms for IOS and android. I am able to change the background color of the cell but is there any way to set any background image to an entry cell. Also how to hide the under bar line in android entry cell which comes default.
My custom entry cell in PCl :
<local:MyEntry Placeholder="Placeholder" PlaceholderColor="Grey" TextColor="Black"/>
Yes, you can set any background image to an entry cell.
For IOS you need to do this:
Control.BorderStyle = UITextBorderStyle.None;
UIImage img = UIImage.FromFile("ImageName.png");
Control.Background = img;
For android :
Control.Background = ContextCompat.GetDrawable(Context, Resource.Drawable.ImageName);
In order to hide the underbar in android use this:
Control.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
After doing this you can adjust the height width of background image of entry cell from xaml like this:
<local:MyEntry Placeholder="placeholder" PlaceholderColor="Grey" TextColor="Black" WidthRequest="200" HeightRequest="50"/>

How can I prevent Scrollviewer to scroll back when scrollbarvisibility is set to disabled? wp7

I have created a Scrollviewer in WP7, which harbors 3 usercontrol, each one of which hold as their content XAML created UserControls. This works fine. This scrollviewer should be able to scroll between these items, but make this not possible for the user to scroll. So when an item in one of these contents are clicked upon, the scrollviewer slides left or right depending on the item selected, and bring into view one of the other usercontrols. I use a mediator to accomplish this:
<Grid.Resources>
<Storyboard x:Name="ItemAnimation">
<DoubleAnimation x:Name="ItemAnimationContent"
Storyboard.TargetName="Mediator"
Storyboard.TargetProperty="ScrollableWidthMultiplier"/>
</Storyboard>
</Grid.Resources>
<ScrollViewer Name="ScrollableItemPanel"
Grid.Row="2"
Grid.RowSpan="3"
Grid.ColumnSpan="3"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Disabled">
<StackPanel Orientation="Horizontal">
<UserControl Name="NewsListBoxControl" Width="480" />
<UserControl Name="DetailedItemControl" Width="480"/>
<UserControl Name="ExternalBrowserItemControl" Width="480"/>
</StackPanel>
</ScrollViewer>
<local:ScrollableItemAnimationMediator x:Name="Mediator"
ScrollViewer="{Binding ElementName=ScrollableItemPanel}"/>
In basic, this works fine too, I can navigate between the items, and load upon them the content as usercontrols. But the problem lies in granting the user the abillity to scroll. Before the item scrolls, I set the hittestvisibilty to true, and the horizontalscrollbarvisibility to visible. After the animation is done, I want to grant back the hittestvisibility and set the horizontalscrollbarvisibility to Disabled again. This latter is where the problem is: when I set the horizontalscrollbarvisibility to Disabled, the scrollviewer automatically brings back into view the first of three items in the stackpanel. How can I stop this? This is the code I use to scroll the mediator:
private void CreateDetailedArticleItem( Dictionary<string, string> itemQuery )
{
_articleDetailPage.ItemQuery = itemQuery;
DetailedItemControl.Content = _articleDetailPage as UserControl;
Animate( _articleDetailPage, 0.0f, 0.5f, 250 );
}
private void Animate( IContentControl control, float from, float to, double milliseconds )
{
//this eventhandler will fire when the animation has completed
EventHandler handler = null;
//we take away the User Input just for the moment, so that we can animate without the user interfering. Also, we make horizontalScroll Visible
IsUserEnabled = false;
//we then set the content of the animation. Where from will it move, towards where and in what duration?
ItemAnimationContent.From = from;
ItemAnimationContent.To = to;
ItemAnimationContent.Duration = TimeSpan.FromMilliseconds( milliseconds );
//we start the animation
ItemAnimation.Begin( );
//we tell the new control that it will appear soon, so it can load its main content
control.ViewWillAppear( );
//also, we tell the currentcontrol that it will disappear soon, so it can unload its content and eventhandlers and so on
CurrentControl.ViewWillDisAppear( );
//the handler is a delegate. This way, it becomes rather easy and clean to fire the completed event, without creating a strong reference ( well, actually,
//we do create a strong reference, but as soon as it is fired, we remove it again, shhhh! ).
handler = delegate( object sender, EventArgs e )
{
//as stated, we remove the eventlistener again, so it won't keep firing all the time
ItemAnimation.Completed -= handler;
//after the animation, we tell the new control that it is now in screen, and can start downloading its data
control.ViewDidAppear( );
//at the same time, the "current" control has fully moved out of view, so it can now fully unload all its content.
CurrentControl.ViewDidDisAppear( );
//now, all we have to do is to make sure that the next time an item is being loaded, the new content is spoken to, not the old one
CurrentControl = control;
//and finally, enable the users input again, and remove the horizontal scrollbarvisibility
IsUserEnabled = true;
};
ItemAnimation.Completed += handler;
}
private bool IsUserEnabled
{
set
{
//when the user can control the scrollviewer, then the horizontal scrollvisibility is disabled, so that the user cannot move horizontally,
//otherwise, so we only make it visible when the program needs to animate.
ScrollableItemPanel.IsHitTestVisible = value;
ScrollableItemPanel.HorizontalScrollBarVisibility = value ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Visible;
}
}
I had already asked this question, then regarded it as answered, as I thought it to be answered, namely using ScrollbarVisibility.Hidden instead of ScrollbarVisibility.Disabled, only the scrollbarvisibility stays visible this way, and the user can still scroll. Is there a native way to deal with this problem?
Any help would be greatly appreciated. Greetz
Rather than fight the behavior of the native control it may be easier to just manipulate the position of items yourself using a custom control (wrapping your other controls) which animates between different visual states (adjust the translate transform) depending on the "selected" item.

Appcelerator titanium, how can I create a modal window?

I am new to appcelerator titanium and have a question
how can I create a modal window that blurs its parent, or have a semi transparent background?, I managed to create a modal window but the parent went black.
thanks in advance
This is the current way to accomplish this in Titanium as of 3.1.3 on iOS.
First, make a new window.
var myModal = Ti.UI.createWindow({
title : 'My Modal',
backgroundColor : 'transparent'
});
Then create a wrapper view, a background view, and a container view:
var wrapperView = Ti.UI.createView(); // Full screen
var backgroundView = Ti.UI.createView({ // Also full screen
backgroundColor : '#000',
opacity : 0.5
});
var containerView = Ti.UI.createView({ // Set height appropriately
height : 300,
backgroundColor : '#FFF'
});
var someLabel = Ti.UI.createLabel({
title : 'Here is your modal',
top : 40
});
var closeButton = Ti.UI.createButton({
title : 'Close',
bottom : 40
});
closeButton.addEventListener('click', function () {
myModal.close();
});
Now build your UI stack. The order is important to avoid having to set z-index.
containerView.add(someLabel);
containerView.add(closeButton);
wrapperView.add(backgroundView);
wrapperView.add(containerView);
myModal.add(wrapperView);
Now you can open your modal, but to NOT set modal : true
myModal.open({
animate : true
});
Its very simple.Just create the window, and when you're opening it,specify the 'modal' property as true!
var ModalWindow = Ti.UI.createWindow({});
ModalWindow.open({modal:true});
In Titanium Appcelerator (tried in 1.6.2) a modal window is always a full screen window. The parent might seem black because this modal window's background is black.
Try specifying a semi-transparent image as the background of this modal window, you are creating and you might get the effect you want from it.
You could try using the opacity on the window you have that is overlaying the other.
Ti.UI.currentWindow.opacity = 0.4;
If you are on iPhone, probably you cannot make it. on iPhone, if a modal dialog appears, the other window on the render stack will be cleared. That is, only ONE modal dialog in the render stack. That's the reason you got black if other areas of the parent are not covered by your modal window. iPad implemented modal dialog using "sheet" style, so you can make the are areas semi transparent.
I like the solution presented by AlienWebguy, although I think there's a minor bug. When you create your label, I think you meant to set the text property and not the title property:
var someLabel = Ti.UI.createLabel({
text: 'Here is your modal',
/* etc., etc. */
});
When I used title, it (the label) was not appearing in the window.
Another modification I might make is to set the layout property for the container view, e.g.,
var containerView = Ti.UI.createView({
height: 100, /* or whatever is appropriate */
backgroundColor : '#FFF',
layout: 'vertical'
});
In doing this, you can "stack" up the GUI elements in that view and not worry (too much) about setting layout coordinates... At least that's what I do in creating a customized alert box using the techniques outlined here.
i was also looking for such window with semi transparent background for ios 8.4. I tried the way "AlienWebguy" in Alloy XMl but the issue was whole window getting opacity 0.5 and background stacked window content are clearly visible than foreground view content. i have did some changes to the "AlienWebguy" to get the required result:
<Alloy>
<Window backgroundColor="transparent" modal="false">
<View layout="vertical" width="Ti.UI.FILL" height="Ti.UI.FILL" backgroundColor="#000" opacity="0.5">
// View will fill whole window with transparent shade of black color.
</View>
<View class="container" zIndex="100" height="400" width="Ti.UI.FILL" backgroundColor="#fff">
// You can add any content here, which will be look like Modal window.
//View automatically vertically centered on screen.
</View>
</Window>
</Alloy>
Hope this will save the time of developer doing in Alloy. Thanks for "AlienWebguy" for the concept.
why not just give it transparent background?
<Window backgroundColor="#80000000">
<View class="container">
// Your views
</View>
</Window>

Resources