I have a Form in which there are many labels and textfield. So I'm navigating within the textfield or entry by clicking on tab button in my keyboard. The normal entry is getting focused on single click whereas the AutoSuggestBoxView which is a custom entry needs two clicks on tab to get focused. I don't know why I'm facing this issue. I have applied tabindex as 0 and -1 but still it is not working.This is my xaml code
<CtrlUC:UCCurrentLocation Grid.Row="0" HeightRequest="32" Grid.Column="0" Latitude="{Binding FieldsData.fromlatitude.Value,Mode=TwoWay}" Longitude="{Binding FieldsData.fromlongitude.Value,Mode=TwoWay}" Grid.RowSpan="2" Grid.ColumnSpan="2" HorizontalOptions="Fill" VerticalOptions="Fill" WidthRequest="400" Title="Location" LatitudeTitle="Latitude" LongitudeTitle="Longitude" ButtonText="Location" IsEditable="False" IsVisible="{Binding Path=FieldsData.FromLocationControl.IsVisible, Mode=TwoWay}" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromState" Grid.Row="1" Grid.Column="2" TabIndex="-1" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromState.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromState.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromState.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromState.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromStateSelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromstatePropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromstatename.Value, Mode=TwoWay}" Placeholder="Enter State" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromState.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="3" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromstatecode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromStateCodeValue.IsVisible, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromCity" Grid.Row="1" Grid.Column="4" TabIndex="" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromCity.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromCity.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromCity.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromCity.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromCitySelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromcityPropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromcityname.Value, Mode=TwoWay}" Placeholder="Enter City" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromCity.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="5" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromcitycode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromCityCodeValue.IsVisible, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromCounty" Grid.Row="1" Grid.Column="6" TabIndex="0" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromcounty.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromcounty.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromcounty.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromcounty.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromCountySelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromcountyPropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromcountyname.Value, Mode=TwoWay}" Placeholder="Enter County" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromcounty.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="7" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromcountycode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromCountyCodeValue.IsVisible, Mode=TwoWay}" />
So as you can see in code the normal entry like CCEntry takes only one tab click. But the custom entry AutoSuggestBoxView takes two clicks on tab to get focused.I have no clue how to fix this. Any suggestions?
There is only one way to avoid multiple clicks in xamarin.forms is you have to use a boolean flag as shown below
public class MyPage : ContentPage
{
public isClicked = false;
public MyPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
isClicked = false;
}
private void ItemTapped(object sender, System.EventArgs e)
{
if(isClicked)
return;
isClicked = true;
//Do your work here
}
}
I am using this way to avoid multiple clicks.
Related
I'm unable to undestand how to access data in CollectionView DataTemplate generated child controls. My XAML code is below. I want to get RadioButton values of all items. Please give me some ideas.
<CollectionView x:Name="ItemsListView"
ItemsSource="{Binding Questions}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="10" >
<Label Text="{Binding Category}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
<Label Text="{Binding Text}"
LineBreakMode="WordWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
<Grid HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<RadioButton Content="Yes" Grid.Column="1" Style="{DynamicResource ListItemTextStyle}"/>
<RadioButton Content="No" Grid.Column="2" Style="{DynamicResource ListItemTextStyle}"/>
<RadioButton Content="N/A" Grid.Column="3" Style="{DynamicResource ListItemTextStyle}"/>
</Grid>
<Editor x:Name="comment" Text="" AutoSize="TextChanges" Style="{DynamicResource ListItemTextStyle}" />
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
As Jason and Steve suggested,the best practice is using MVVM.
Below is code snippet for your reference:
In your XAML:
<RadioButton Content="Yes" Grid.Column="1" IsChecked="{Binding YesChecked}" Style="{DynamicResource ListItemTextStyle}"/>
<RadioButton Content="No" Grid.Column="2" IsChecked="{Binding NoChecked}" Style="{DynamicResource ListItemTextStyle}"/>
<RadioButton Content="N/A" Grid.Column="3" IsChecked="{Binding N_AChecked}" Style="{DynamicResource ListItemTextStyle}"/>
Then in your view model,use like below:
public bool yesChecked;
public bool YesChecked
{
get { return yesChecked; }
set
{
yesChecked = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("YesChecked"));
}
}
I have an Expander in a CollectionView.
I try to select a radio button in every row but everytime I scroll multiple rows displaying the same radio button as selected even though the row is not selected. I am using xamarin forms 5.0.0.1874
here is my code
<CollectionView ItemsSource="{Binding sI_Refill_s}">
<CollectionView.ItemTemplate>
<DataTemplate>
<yummy:PancakeView CornerRadius="10" BackgroundColor="{StaticResource GreenColor}" Padding="10">
<xct:Expander IsExpanded="{Binding IsEnable}">
<xct:Expander.Header>
<Grid RowDefinitions="Auto,Auto" ColumnDefinitions="*,*,*" RowSpacing="10" Padding="05">
<!--ROW1-->
<Label Grid.Row="0" Grid.Column="0" Text="Last" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="1" Text="DOB" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="2" Text="Reason" Style="{StaticResource headerStyle}"/>
<!--ROW2-->
<Label Grid.Row="1" Grid.Column="0" Text="{Binding Last}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding DOB}" Style="{StaticResource ValStyle}"/>
<Entry Grid.Row="1" Grid.Column="2" Text="{Binding Reason, Mode=TwoWay}" HorizontalOptions="Fill" Style="{StaticResource ValStyle}"/>
</Grid>
</xct:Expander.Header>
<xct:Expander.ContentTemplate>
<DataTemplate>
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="*,*,*,*,*" RowSpacing="10">
<!--ROW3-->
<Label Grid.Row="0" Grid.Column="0" Text="First" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="1" Text="L_DISP_DT" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="2" Text="REM_INJS" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="3" Text="STATUS" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="4" Text="Refill#" Style="{StaticResource headerStyle}"/>
<!--ROW4-->
<Label Grid.Row="1" Grid.Column="0" Text="{Binding First}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding L_Disp_Dt}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="2" Text="{Binding Rem_injs}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="3" Text="{Binding Status}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="4" Text="{Binding RefillNo}" Style="{StaticResource ValStyle}"/>
<!--ROW5-->
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5" Text="Decision" Style="{StaticResource headerStyle}"/>
<!--ROW6-->
<StackLayout Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5"
RadioButtonGroup.GroupName="{Binding groupName}"
RadioButtonGroup.SelectedValue="{Binding SelectedItem}" Orientation="Horizontal" HorizontalOptions="Center">
<RadioButton Content="Approved"
Value="Approved" FontSize="Micro"/>
<RadioButton Content="Hold"
Value="Hold" FontSize="Micro"/>
<RadioButton Content="Reject"
Value="Reject" FontSize="Micro"/>
</StackLayout>
</Grid>
</DataTemplate>
</xct:Expander.ContentTemplate>
</xct:Expander>
</yummy:PancakeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
If you are targeting iOS then it is likely to be XamarinCommunityToolkit bug you can follow it status/progress in:
Expander within CollectionView does not work properly on iOS #608
Expander is not expanding and collapsing properly when load in CollectionView #572
I have a listview for displaying all the items that i getting from api.i have a live event which will modify one field inside the item of type observablecollection
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Dyocense.Views.ManageJobs"
Title="All jobs">
<ContentPage.ToolbarItems>
<ToolbarItem Text="ADD" Clicked="AddJob"></ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout>
<SearchBar x:Name="Search" SearchButtonPressed="SearchBar_SearchButtonPressed"></SearchBar>
<ListView x:Name="JobsListView"
ItemsSource="{Binding Items}"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
CachingStrategy="RecycleElement"
ItemAppearing="BrowseJobList_ItemAppearing"
IsPullToRefreshEnabled="true"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Frame HasShadow="True" >
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Name}"
Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
FontSize="Medium"
FontAttributes="Bold"/>
<Label Text="Status"
Grid.Row="1" Grid.Column="0"
FontSize="16"
FontAttributes="Bold"/>
<Label Text="{Binding Status}"
Grid.Row="1" Grid.Column="1"
FontSize="16"/>
<Label Text="Goal"
Grid.Row="2" Grid.Column="1"
FontSize="16"
FontAttributes="Bold"/>
<Label Text="{Binding Goal}"
Grid.Row="2" Grid.Column="2"
FontSize="16" />
<Label Text="Part"
Grid.Row="3" Grid.Column="1"
FontSize="16"
FontAttributes="Bold"/>
<Label Text="{Binding PartName}"
Grid.Row="3" Grid.Column="2"
FontSize="16" />
<Label Text="Assembly"
Grid.Row="4" Grid.Column="1"
FontSize="16"
FontAttributes="Bold"/>
<Label Text="{Binding NodeName}"
Grid.Row="4" Grid.Column="2"
FontSize="16" />
<Label Text="GoodCount"
Grid.Row="5" Grid.Column="0"
FontSize="16"
FontAttributes="Bold"/>
<Label Text="{Binding GoodCount}"
Grid.Row="6" Grid.Column="0"
FontSize="16"
HorizontalTextAlignment="Center"/>
<Label Text="RejectCount"
Grid.Row="5" Grid.Column="1"
FontSize="16"
FontAttributes="Bold"/>
<Label Text="{Binding RejectCount}"
Grid.Row="6" Grid.Column="1"
FontSize="16"
HorizontalTextAlignment="Center"/>
<Label Text="DownTimeCount"
Grid.Row="5" Grid.Column="2"
FontSize="16"
FontAttributes="Bold"/>
<Label Text="{Binding DownTimeCount}"
Grid.Row="6" Grid.Column="2"
FontSize="16"
HorizontalTextAlignment="Center"/>
</Grid>
</StackLayout>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<Grid Padding="6" IsVisible="{Binding IsBusy}">
<!--set the footer to have a zero height when invisible-->
<Grid.Triggers>
<Trigger TargetType="Grid" Property="IsVisible" Value="False">
<Setter Property="HeightRequest" Value="0" />
</Trigger>
</Grid.Triggers>
<!--the loading content-->
<Label Text="Loading..." VerticalOptions="Center" HorizontalOptions="Center" />
</Grid>
</ListView.Footer>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
i want to update the good count on real time. i debugged the code its getting updated in my list but only updating the UI on a user scroll. Here is my viewmodel
public class JobViewModel: INotifyPropertyChanged
{
private ObservableCollection<Job> items;
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<Job> Items
{
get { return items; }
set
{
items = value;
if (items != value)
{
items = value;
OnPropertyChanged(nameof(Items));
}
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
private void updateJoblistOnEvent(NotificationEntity message)
{
var jobId = message.JobId;
Job job = Items.FirstOrDefault(a => a.JobId.Equals(jobId));
switch (message.EventCode)
{
case MessageTypeEnum.Pulse: //Pulse
job.GoodCount = job.GoodCount + 1;
//job.Status = 'Running';
break;
default:
break;
}
}
i am suspecting two things
CachingStrategy="RecycleElement" i removed this one that its not updating with scroll also
any problem with INotifyPropertyChanged, i tried to remove one item from list its working and updating the ui.i want to update the field inside the item
can any one help me
As deduced from the comments, you need to also implement the INotifyPropertyChanged interface on the Job object. Using the ObservableCollection only helps for changes in that collection, so when you remove or add a Job object, not if something changes inside the Job object.
So, in your Job object do this (code reverse engineered from what you posted):
public class Job : INotifyPropertyChanged
{
private int goodCount;
public int GoodCount
{
get { return goodCount; }
set
{
if (goodCount != value)
{
goodCount = value;
OnPropertyChanged(nameof(GoodCount));
}
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
You could remove the INotifyPropertyChanged from your JobViewModel, but you probably need it there at some point as well
I want to select the list item when I click the button(Which is inside the list box for every row).
Now I have try like this:-
<ListBox Height="444"
ItemsSource="{Binding StudentDetails,Mode=TwoWay}"
HorizontalAlignment="Left" Margin="2,34,0,0"
Name="listBox1" VerticalAlignment="Top"
Width="476" BorderBrush="#00410D0D"
SelectedIndex="{Binding MemberPrivacy,Mode=TwoWay}"
SelectedItem="{Binding SelectedStudent, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray" Padding="5" BorderThickness="1">
<StackPanel Orientation="Horizontal">
<Border BorderBrush="Wheat" BorderThickness="1">
<Image Name="ListPersonImage" Source="{Binding PersonImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,0,0,0"/>
</Border>
<TextBlock Text="{Binding FirstName}" Name="firstName" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22" />
<Image Height="50" Source="{Binding addImage}" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="50" />
<Button Margin="-100,0,0,0" Height="80" Width="80" DataContext="{Binding DataContext, ElementName=listBox1}" Command="{Binding addPerson}" >
<Button.Background>
<ImageBrush ImageSource="{Binding addImage, Converter={StaticResource pathToImageConverter}}" Stretch="Fill" />
</Button.Background>
</Button>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My View Model:-
public ListBoxEventsViewModel()
{
addPerson = new ReactiveAsyncCommand();
addPerson.Subscribe(x =>
{
MessageBox.Show("Test Button Selected..");
});
}
Here I can show the message box when I click the button. But I can not select the list item. Please let me know to solve this problem.
Thanks in advance.
View Model:-
List box selected Item:-
public ListBoxEventsModel _SelectedStudent;
public ListBoxEventsModel SelectedStudent
{
get { return _SelectedStudent; }
set
{
this.RaiseAndSetIfChanged(x => x.SelectedStudent, value);
MessageBox.Show("Selected index==>" + SelectedStudent.FirstName);
}
}
Here it showing the selected name when I click the list item. But this same thing I want to write it for the button(addImage)
Bind the SelectedItem on the ListBox to a "SelectedItem" property on the ViewModel.
eg SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
then on the view model just add a property of SelectedItem, then you can just set that from in your subscribe.
I am getting the following error with my code shown below.
Error:
The property 'Content' is set more than once
Code:
<controls:PanoramaItem Header="headlines">
<TextBlock Text="{Binding Tones}" />
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Tones}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<Image Source="{Binding ImageUrl}" Height="75" Width="100"
Margin="12,10,9,0" VerticalAlignment="Top"/>
<StackPanel Width="311">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap"
Style="{StaticResource PhoneTextLargeStyle}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
A PanoramaItem can only have one child control but you currently have a TextBlock and a ListBox. To fix this, simply add another parent control to hold the TextBlock and ListBox (such as a StackPanel or a Grid). For example:
<controls:PanoramaItem Header="headlines">
<grid>
<TextBlock Text="{Binding Tones}" />
<!--Double line list with image placeholder and text wrapping-->
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Tones}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Image Source="{Binding ImageUrl}" Height="75" Width="100" Margin="12,10,9,0" VerticalAlignment="Top"/>
<!--<Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/>-->
<StackPanel Width="311">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}"/>
<!--<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>-->
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</grid>
</controls:PanoramaItem>