This question already has an answer here:
Bind command on IsChecked RadioButton property
(1 answer)
Closed last year.
RadioButton command property not working after updated from Xamarin.Forms 4.7 to Xamarin.Forms 5.0.0.2337. what are the alternative ways to use command in ViewModel not with codebehind.
Yes,since Xamarin.Forms 5.0.0, the property Command has been removed from RadioButton.
If you want to run a command upon state change then you can use the event CheckedChanged.
<RadioButton Content="test">
<RadioButton.Behaviors>
<local:EventToCommandBehavior EventName="CheckedChanged" Command="{Binding Source={x:Reference Page}, Path=BindingContext.RadioCommand}" CommandParameter="V"/>
</RadioButton.Behaviors>
</RadioButton>
For EventToCommandBehavior.cs, you can refer sample code here: https://github.com/xamarin/xamarin-forms-samples/tree/main/Behaviors/EventToCommandBehavior/EventToCommandBehavior/Behaviors .
Note:
Page is the x:Name of current page.
Related
I am using Xamarin Forms Shell and I want to be able to hide some items of my Flyout depending on some parameters (the current page for instance) but I can't find any method or property to change the visibility of a FlyoutItem.
Is it possible to programmaticaly hide some FlyoutItem (not the complete Flyout just some items) ?
As of this moment it is not possible, there is a current Issue regarding this.
However, I managed to find another thread, where there might be a solution with dynamic creating flyout items. You can check it here.
It is possible with Xamarin.Forms 4.8 version.
you can use Isvisible attribute to show/hide any flyout item.
Please refer below link for more details :
Xamarin.Forms v4.8
GitHub Issue Resolved
Had the same issue, here is my solution.
I created a style, and set that to hidden.
Then I update my MenuItem in the backend, depending what is needed.
Style
<Style
ApplyToDerivedTypes="True"
Class="MenuItemLayoutStyleHidden"
TargetType="Layout">
<Setter Property="IsVisible" Value="False" />
</Style>
Menu Item
<MenuItem
x:Name="btnLogout"
Clicked="btnLogoutClick"
IconImageSource="icon_about.png"
StyleClass="MenuItemLayoutStyle"
Text="Logout" />
Backend Code
if (user.isLoggedIn)
{
btnLogout.#class.Clear();
btnLogout.#class.Add("MenuItemLayoutStyle");
}
else
{
btnLogout.#class.Clear();
btnLogout.#class.Add("MenuItemLayoutStyleHidden");
}
this works for me
flyoutxname.FlyoutItemIsVisible = false;
where flyoutxname is the x:Name property for the flyoutitem.
<FlyoutItem Title="item title" x:Name="flyoutxname" Icon="byebye.jpg">
source
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/flyout
I was searching how i can hide a MenuItem in Shell Flyout because i didn't want to use FlyoutItem. I needed the Clicked event. I managed to hide a MenuItem with:
<MenuItem Text="Arrivals" x:Name="Arrivals" Clicked="MenuItem_Clicked" Shell.FlyoutItemIsVisible="False"/>
This is just as the title suggests. I've updated my Xamarin Forms project to a 1.6 NetStandard project and now the tapped event on my SfListView isn't working (It just doesn't fire at all).
Does anyone has any suggestions of what could be wrong or have faced anything like this?
EDIT
this is xaml code for SfListView:
<StackLayout HeightRequest="15" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<xForms:SfListView Orientation="Horizontal" ItemSize="128" ItemsSource="{Binding Categories}" SelectionBackgroundColor="Transparent" IsScrollBarVisible="False">
<xForms:SfListView.ItemTemplate>
<DataTemplate>
<cells:CategoryCell />
</DataTemplate>
</xForms:SfListView.ItemTemplate>
<xForms:SfListView.Behaviors>
<behaviors:SfSelectedItemBehavior Command="{Binding FilterCommand}" />
</xForms:SfListView.Behaviors>
</xForms:SfListView>
</StackLayout>
this structure was working before the update. I use a behavior for item selection.
We have checked with the reported query “SfListView ItemTapped event does not trigger after updating the NetStandard Library” from our side. Unfortunately the reported issue does not occur at our end and the ItemTapped event is fired as expected.
For your reference, we have attached the working sample link below.
Sample link: http://www.syncfusion.com/downloads/support/directtrac/190562/ze/SfListViewSample-670965361
Can you please check in your device whether the issue reproduces in our sample also?
If so, Can you please share the below details?
Whether the reported issue occurs in particular device or all devices? (Can you please share the details of your tested device)
Whether the issue is produced in particular platform?
Whether the issue is produced in particular version of Xamarin.Forms and SfListView? (In our sample, we used XForms (v2.3.4.280) and SfListView(v15.3.0.33))
Also can you please share the share the template in which the SfListView items are loaded?
I'm getting an issue I don't understand. I have a Button with an image defined with the following code :
<Button Image="SearchFilterIcon.png"
Grid.Row="0"
Grid.Column="1"
Clicked="OnButtonFilterClicked" />
This works well on Android. The image is displayed on my button but when I launch the Windows Phone application, I get a XamlParseException which says that : No Property of name Image found.
How is it possible? The Button widget isn't the same on Android and Windows Phone?
If you do the following:-
Button objButton1 = new Button();
objButton1.Image = (FileImageSource)ImageSource.FromFile("testImage1.png");
objStackLayout.Children.Add(objButton1);
this.Content = objStackLayout;
Then it will work (via code-behind).
The Button control always had the Image property, even in Xamarin.Forms v1.2.2x, so this is not a new property introduced and nothing to do with having the latest packages installed.
As a workaround perhaps you should consider giving the XAML Button a x:Name as in:-
<Button x:Name="myButton1"/>
And then assign the image from code-behind:-
myButton1.Image = (FileImageSource)ImageSource.FromFile("testImage1.png");
Update 1
This was a case of very old libraries being used (v1.0.6186). Once the project is reupdated to the latest binaries for v1.2.3x, then this works fine.
The Button.Image is available on WP, just as it is on iOS and Android. You probably don't have the latest nuget (1.2.3) installed for WP, or you have multiple versions installed.
The buttons in XAML for Windows Phone simply do not provide an Image property. Thus, you cannot add an image to the button as the API doesn't support this. What you have to do is to create a control template that contains the text and the image.
Button documentation
Try some like:
<Button Click="OnButtonFilterClicked">
<Button.Background>
<ImageBrush Stretch="Fill" ImageSource="/SearchFilterIcon.png"/>
</Button.Background>
</Button>
instead of "Clicked" and "image" properties.
I have a DataGrid with some text columns and a button. I want to bind button to a command on the ViewModel. Since, Columns are inside the context of the ItemSource, i want to change the DataContext for the button to something outside the DataGrid(to a view model, to access the Command) or else Silverlight is not able to find the binding expression for that command on the ItemSource context.
Here is what i am doing but i am unsuccessful in doing so. I am not sure where i am making a mistake
<DataGrid >
...
<Button>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding Path=DataContext.CommandToCall, ElementName=DataGridName}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
...
</DataGrid>
I do not get any Binding error on doing this but i cannot invoke the command inside my ViewModel. Please note, it is for silverlight and not WPF.
Thanks
I had this same problem recently. I was using a Telerik RadGridView, and I found a workaround on their support forum. Maybe you can do something similar.
Here's the question, and here's the workaround.
Before I explain my issue, consider the following object:
Character.cs
-> AnimationControlSettings.cs
.. -> UpControlType (string)
.. -> AvailableControlTypes (List<string>)
The relevant properties in my ViewModel:
Character SelectedCharacter
ObservableCollection<Character> Characters
I have a simple View where you select a character using a ComboBox. The ComboBox's SelectedItem is TwoWay-bound to the ViewModel's SelectedCharacter property. There are other textboxes/checkboxes (also two-way bound to various properties of SelectedCharacter) that maintain their values properly as I switch between Characters.
The problem exists in the ComboBox bound to the UpControlType property:
<ComboBox x:Name="lstUpControlTypes"
ItemsSource="{Binding Path=SelectedCharacter.AnimationControlSettings.AvailableControlTypes}"
SelectedItem="{Binding Path=SelectedCharacter.AnimationControlSettings.UpControlType, Mode=TwoWay}">
</ComboBox>
Initial values are displayed in this ComboBox correctly but as soon as I switch from CharacterA to CharacterB, CharacterA's UpControl property is set to NULL and I have no idea why.
Here is a barebones repro of this exact issue (VS2010, SL4):
http://www.checksumlabs.com/source/TwoWayBindingWorkshop.zip
If you run that solution you'll see that the Name property persists as you switch Characters but the UpControlType value's getting set to NULL.
Am I missing something obvious here?
You are binding the items source of the third combo box to a property inside the SelectedCharacter, like this:
ItemsSource="{Binding SelectedCharacter.AnimationControlSettings.AvailableControlTypes}"
This means that when SelectedCharacter changes the items source for that combo box will be reset and this activates the two way binding you set in the SelectedItem of the same combo box, setting your property to null:
SelectedItem="{Binding SelectedCharacter.AnimationControlSettings.UpControlType, Mode=TwoWay}"
I was able to fix the issue by moving the property AvailableControlTypes to the CharacterViewModel class, which means that when you change the character, the available types remain the same. If this is acceptable in your situation, it will fix your problem:
<ComboBox x:Name="lstUpControlTypes"
ItemsSource="{Binding AvailableControlTypes}"
SelectedItem="{Binding SelectedCharacter.AnimationControlSettings.UpControlType, Mode=TwoWay}" />