I have swipe views in a list. in there I got scrolling issue so I want to get offSet of the swipe view
How do I determine swipe view offset in xamarin forms?
We can easily use SwipeChanging event and it's include the SwipeDirection property and offSet property of the swipe view. 😀
private void SwipeView_OnSwipeChanging(object sender, SwipeChangingEventArgs e)
{
e.offSet = 50;
}
Related
Is there an Image Button Renderer in Xamarin.MacOS?
I am using Xamarin.Forms and all my image buttons in the common code are not shown at all in Xamarin.MacOS. Is Image Button supported in Xamarin.MacOS?
Is there an Image Button Renderer in Xamarin.MacOS?
Unfortunately, after checking the source code of Xamarin.Forms.Platform.macOS, there is no ImageButtonRenderer there now. I guess the reason that there is no control is the similar with ImageButton. I'm not sure whehter designer will add this in the future. Whatever, now it not exists.
Is Image Button supported in Xamarin.MacOS?
From the above said, MacOS has no control like ImageButton of Forms. Therefore, if used ImageButton in Xamarin Froms, it will not show in Xamarin.MacOS.
However, there is a workaround. You could use Button in Forms, and add Image in ButtonRenderer in Xamarin.MacOS. Because NSButton has a Image property.
For example, the code of ButtonRenderer as follows:
[assembly: ExportRenderer (typeof(MyButton), typeof(MyButtonRenderer))]
namespace CustomRenderer.MacOS
{
public class MyButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Button> e)
{
base.OnElementChanged (e);
if (Control != null) {
// do whatever you want to the UITextField here!
Control.Image= NSImage.ImageNamed("tree")
Control.ImageScaling = NSImageScale.AxesIndependently;
}
}
}
}
The image source (tree.png) is the same way with iOS to be added in Resource folder, and set Propertied : Build Action -> BundleResource.
I have a popup on click of a list view.
Is it possible to include Tabbed page in the popup with two tabs?
Not sure what effect is your want.Follow is one way :
async void OnAlertYesNoClicked (object sender, EventArgs e)
{
bool answer = await DisplayAlert ("Question?", "Would you like to play a game", "Yes", "No");
Debug.WriteLine ("Answer: " + answer);
}
If you want tabs without having a TabbedPage in Xamarin.Forms, you can use those custom tabs:
https://github.com/roubachof/Sharpnado.Presentation.Forms#pure-xamarinforms-tabs-no-renderers
These are simple xamarin forms views, you can put them everywhere you like.
I noticed that after using the .HeightRequest property on a View in Xamarin.Forms that a method I have assigned to the SizeChanged event is no longer called.
The content within the View that had called .HeightRequest is a Label that contains text which can be zoomed in. When zooming in, the text now exceeds the "bounds" of the View's height, and the height is no longer adjusting as it once was.
public ExpandableEntryView(...)
{
InitializeComponent();
// my beautiful code
SizeChanged += ExpandableEntryView_SizeChanged;
UpdateUI();
}
private void ExpandableEntryView_SizeChanged(object sender, EventArgs e)
{
// this is never called once .HeightRequest is assigned a value
}
private void SomeFunction() {
sectionsStackLayout.HeightRequest = 0; // this causes SizeChanged to no longer work
}
I essentially need this View to minimize its height to 0, and then return to its original height when I tell it to. I am also using IsVisible, but the Height property is required for an animation I am trying to do.
Thank you in advance.
Nevermind, I was able to figure it out. The reason why the SizeChanged event is no longer called is because the view is no longer responsible for keeping track of its size after assigning a value to HeightRequest. So, if you would like for your View to return to being able to determine its own size once again, (i.e. if a child element in that View happens to change size/scale) you need to assign the HeightRequest to -1. This will then reenable the SizeChanged event.
Hope this helps somebody!
I have implemented a custom clickable label class in Xamarin.Forms along with a custom renderer, that adds a RippleDrawable as the controls Foreground. I am creating the RippleDrawable with the following code:
public static Drawable CreateRippleDrawable(Context context)
{
var typedValue = new TypedValue();
context.Theme.ResolveAttribute(Resource.Attribute.SelectableItemBackground, typedValue, true);
var rippleDrawable = context.Resources.GetDrawable(typedValue.ResourceId, context.Theme);
return rippleDrawable;
}
In my custom renderer I assign the drawable
this.Control.Foreground = DrawableHelper.CreateRippleDrawable(this.Context);
and update the ripple when the user touches the control
private void LinkLabelRenderer_Touch(object sender, TouchEventArgs e)
{
if (e.Event.Action == MotionEventActions.Down)
{
this.Pressed = true;
}
if (e.Event.Action == MotionEventActions.Cancel)
{
this.Pressed = false;
}
if (e.Event.Action == MotionEventActions.Up)
{
this.Ripple.SetHotspot(e.Event.GetX(), e.Event.GetY());
this.Pressed = false;
// raise the event of the Xamarin.Forms control
}
}
Now, whenever I click the control, the ripple will be shown, which is the expected behavior, but if I touch (tap or long-press) the parents of the control (e.g. the StackLayout, Grid or whatever layout contains the label, including their parent Layout, Page or View) the ripple animation will be triggered. Anyway, the event handler LinkLabelRenderer_Touch in not called in this case, only when the actual control is touched.
I can work around this behavior by adding an empty GestureRecognizer to the respective parent(s), but I really dislike this solution, because this is but a hack. And to make things worse it is a hack I'll always have to remember whenever I use the control.
How can I prevent the RippleDrawable being shown when the parent is touched?
Turned out I got things fundamentally wrong. Subscribing the Touch event is not the way to go. I had to make the control clickable and subscribe the Click event
this.Control.Clickable = true;
this.Click += LinkLabelRenderer_OnClick;
There is no need to handle all that RippleTouch stuff the way I did (via the Touch event) but could let android handle things for me.
How to move search icon of search bar at right hand side in xamarin forms.
I am looking for android and IOS.
For Android I used SearchBarRenderer With below code which does not worked
Anyone know how to do it?Please help.
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
Control.LayoutParameters=(new ActionBar.LayoutParams(GravityFlags.Right));
}
In android, with a custom renderer, you can use the following code to place the search icon at the right side of your search bar:
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var searchView = base.Control as SearchView;
//Get the Id for your search icon
int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
ViewGroup linearLayoutSearchView = (ViewGroup)searchViewIcon.Parent;
searchViewIcon.SetAdjustViewBounds(true);
//Remove the search icon from the view group and add it once again to place it at the end of the view group elements
linearLayoutSearchView.RemoveView(searchViewIcon);
linearLayoutSearchView.AddView(searchViewIcon);
}
}
In the above implementation, I simply removed the search icon from the search bar view group and then added it again to the same view group. This placed the normally first child to the last child, thus placing the search icon at the end.