Im having this issue on where Images that are using binding aren't showing up on iOS. All my images are inside a resource folder and then inside a images folder. If I don't use binding on the images they show up just fine On Android the images are showing up just fine
Here is my xaml:
<StackLayout Spacing="0">
<Label x:Name="DisconnectedLabel" TextColor="{AppThemeBinding Dark={StaticResource Secondary}, Light={StaticResource Accent}}"
Text="Disconnected From Server" IsVisible="false" BackgroundColor="DarkRed"
HorizontalTextAlignment="Center"
FontSize="16">
</Label>
<RefreshView x:DataType="local:MowersViewModel" Command="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
<CollectionView BackgroundColor="{AppThemeBinding Dark={StaticResource Accent}, Light={StaticResource Secondary}}" x:Name="ItemsListView"
ItemsSource="{Binding Items}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid RowDefinitions="90" ColumnDefinitions="90,90,*" x:DataType="model:Mower" BackgroundColor="{AppThemeBinding Dark={StaticResource Accent}, Light={StaticResource Secondary}}">
<Image Grid.Row="0" Grid.Column="0" x:DataType="model:Mower" Source="{Binding MowersPageImage}" Aspect="AspectFill" Margin="5"/>
<VerticalStackLayout Grid.Row="0" Grid.Column="1" VerticalOptions="Center" Padding="0,10,0,0">
<Label Text="{Binding MachineSerialNumber}"
LineBreakMode="NoWrap" TextColor="{AppThemeBinding Dark={StaticResource Secondary}, Light={StaticResource Accent}}"
FontSize="16" />
<Label Text="{Binding CompanyName}"
LineBreakMode="NoWrap" TextColor="{AppThemeBinding Dark={StaticResource Secondary}, Light={StaticResource Accent}}"
FontSize="13" />
</VerticalStackLayout>
<HorizontalStackLayout Grid.Row="0" Grid.Column="2" Margin="5" x:DataType="model:Mower" HorizontalOptions="End" BackgroundColor="{AppThemeBinding Dark={StaticResource Accent}, Light={StaticResource Secondary}}">
<Button x:Name="ButtonConfigure" Margin="0,0,5,0" Text="Configure" HeightRequest="45" IsVisible="{Binding CanConfigure}"
Command="{Binding Source={RelativeSource AncestorType={x:Type local:MowersViewModel}}, Path=ConfigurePushed}"
CommandParameter="{Binding .}"/>
<Button x:Name="ButtonConnect" Text="{Binding ConnectButtonString}" IsVisible="{Binding Online}" HeightRequest="45"
Command="{Binding Source={RelativeSource AncestorType={x:Type local:MowersViewModel}}, Path=ConnectPushed}"
CommandParameter="{Binding .}"/>
</HorizontalStackLayout>
<Grid.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="1"
Command="{Binding Source={RelativeSource AncestorType={x:Type local:MowersViewModel}}, Path=ItemTapped}"
CommandParameter="{Binding .}">
</TapGestureRecognizer>
</Grid.GestureRecognizers>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</StackLayout>
Here is the lines where the images are supposed to be bound too:
async Task ExecuteLoadItemsCommand()
{
IsBusy = true;
try
{
Items.Clear();
// add mowers that we are connected to
var sorted = new List<MowerData>((IEnumerable<MowerData>)online_mowers_);
sorted.Sort((x, y) => (int)x.serial_number - (int)y.serial_number);
foreach (var m in sorted)
{
var new_item = new Mower();
new_item.MachineSerialNumber = m.serial_number.ToString();
new_item.CompanyName = "";// todo fill me in?
new_item.Connected = m.connected;
new_item.OtherUserConnected = m.other_user_connected;
new_item.Online = true;
new_item.AccentColor = m.GetAccentColor();
if (new_item.AccentColor == Color.FromRgb(1, 0, 1))
{
new_item.MowersPageImage = "Resources/Images/mower_active_purple.png";
}
else if (new_item.AccentColor == Color.FromRgb(1, 1, 1))
{
new_item.MowersPageImage = "Resources/Images/mower_active_grey.png";
}
else
{
new_item.MowersPageImage = "Resources/Images/mower_active_blue.png";
}
new_item.CanConfigure = App.IsTechnician || m.connected;
Items.Add(new_item);
}
var items = (await DataStore.GetItemsAsync(true)).ToList();
items.Sort((x, y) => (int)int.Parse(x.MachineSerialNumber) - (int)int.Parse(y.MachineSerialNumber));
foreach (var i in items)
{
bool found = false;
i.MowersPageImage = "Resources/Images/mower_offline.png"; //off
for (int j = 0; j < Items.Count; j++)
{
var item = Items[j];
if (item.MachineSerialNumber == i.MachineSerialNumber)
{
found = true;
item.CompanyName = i.CompanyName;
Items.RemoveAt(j);
Items.Insert(j, item);
break;
}
}
if (!found)
{
i.CanConfigure = false;
Items.Add(i);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
finally
{
IsBusy = false;
}
}
I tried changing all the paths for the image didn't do anything. Then tried a static Image that one worked
A method is to set your images's Build Action to Embedded resource and add a new property MySource in your item.
Just as follows:
public ImageSource MySource { get; set; }
then set value for MySource as follows:
MySource = ImageSource.FromResource("RefreshViewDemo.Resources.Images.sleep.png",typeof(MowersViewModel).GetTypeInfo().Assembly)
And bind like this:
<Image Source="{Binding MySource}" Aspect="AspectFill" WidthRequest="50" HeightRequest="50" />
Note:
RefreshViewDemo is the name of my app,you can change it to yours.
Please change your images' Build Action to Embedded resource
Related
I have tried everything I could find on the internet and still cannot get the event to fire. My page contains 2 buttons as you can see which fire in the Simulator but not on my iphone. I have tried many different solutions found on the internet and the one I am showing here is the last one I attempted.
Here is the buttons defined in my view:
<Button Command="{Binding Source={RelativeSource AncestorType={x:Type ViewModel:EditViewModel}}, Path=UpdateMileage}" CommandParameter="{Binding .}" IsEnabled="True" Text="Update" BackgroundColor="Yellow" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="1" TextColor="Black" Margin="4"/>
<Button Command="{Binding Source={RelativeSource AncestorType={x:Type ViewModel:EditViewModel}}, Path=Cancel}" CommandParameter="{Binding .}" Text="Cancel" BackgroundColor="Yellow" Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="2" TextColor="Black" Margin="4"/>
The viewModel code is as follows;
public ICommand UpdateMileage
{
get; set;
}
public EditViewModel()
{
UpdateMileage = new Command(UpdateMileageData);
MileageTableDefination mileage = new MileageTableDefination();
mileage = Application.Current.Properties["MileageData"] as MileageTableDefination;
SDate = Convert.ToDateTime(mileage.Date);
EntMiles = mileage.Miles.ToString();
EntGas = mileage.Gas.ToString();
EntCost = mileage.Price.ToString();
if (mileage.Note != null)
EntNote = mileage.Note.ToString();
EntId = mileage.Id;
}
public async void UpdateMileageData()
{
Analytics.TrackEvent("In UpdateMileageData Top ");
int autoId = Convert.ToInt32(Application.Current.Properties["autoId"]);
//Analytics.TrackEvent("Mileage Data in Enter Mileage: AutoId " + autoId);
error = false;
IsVisibleLabel = false;
if (EntMiles == "0" || EntMiles == null)
{
error = true;
IsVisibleLabel = true;
EntError = "Miles Driven Must Be Numeric";
}
else if (!System.Text.RegularExpressions.Regex.IsMatch(EntMiles, #"^[0-9]\d*(\.\d+)?$"))
{
error = true;
IsVisibleLabel = true;
EntError = "Miles Driven Must Be Numeric";
}
else if (Convert.ToDecimal(EntMiles) > 1000)
{
error = true;
//IsVisibleLabel = true;
EntError = "Miles Driven Since Last Fillup";
}
if (EntGas == "0" || EntGas == null)
{
error = true;
IsVisibleLabel = true;
EntError = "Gas Used Must Be Numeric";
}
else if (!System.Text.RegularExpressions.Regex.IsMatch(EntGas, #"^[0-9]\d*(\.\d+)?$"))
{
error = true;
IsVisibleLabel = true;
EntError = "Gas Used Must Be Numeric";
}
if (EntCost == "0" || EntCost == null)
{
error = true;
IsVisibleLabel = true;
EntError = "Cost Must Be Numeric";
}
else if (!System.Text.RegularExpressions.Regex.IsMatch(EntCost, #"^[0-9]\d*(\.\d+)?$"))
{
error = true;
IsVisibleLabel = true;
EntError = "Cost Must Be Numeric";
}
else if (Convert.ToDecimal(EntCost) > 300.00m)
{
error = true;
IsVisibleLabel = true;
EntError = "Cost Must Be Numeric And < $300";
}
Analytics.TrackEvent("In UpdateMileageData After If's Error = " + error);
if (!error)
{
miles.Date = SDate.Date;
miles.StrDate = SDate.Date.ToString("MM/dd/yyyy");
miles.Miles = Convert.ToDecimal(EntMiles);
miles.Gas = Convert.ToDecimal(EntGas);
miles.Id = EntId;
miles.CarId = autoId;
miles.MPG = Math.Round(Convert.ToDecimal(EntMiles) / Convert.ToDecimal(EntGas), 3);
miles.Price = Convert.ToDecimal(EntCost);
miles.Note = EntNote;
MileageItemRepository mir = new MileageItemRepository();
var results = await mir.UpdateMileageAsync(miles);
Analytics.TrackEvent("In UpdateMileageData Results = " + results);
if (results == 1)
{
Application.Current.Properties["UpdatedData"] = miles;
var nav = MyNavigation.GetNavigation();
await nav.PushAsync(new ViewMileage());
}
}
}
As you can see from my code I have logging statements and they are never reached. Any help would be much appreciated. Thanks in advance!
EDIT:
Here is the full xaml that contains the buttons
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:Validate="clr-namespace:MileageManagerForms.Validators"
xmlns:ViewModel ="clr-namespace:MileageManagerForms.ViewModels"
x:Class="MileageManagerForms.Views.EditMileage">
<ContentPage.BindingContext>
<ViewModel:EditViewModel/>
</ContentPage.BindingContext>
<Grid BackgroundColor="Purple">
<Grid.RowDefinitions>
<RowDefinition Height="47"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="45"/>
<RowDefinition Height="45"/>
<RowDefinition Height="30"/>
<RowDefinition Height="45"/>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="85"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="15"/>
<ColumnDefinition Width="85"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<Frame BackgroundColor="#2196F3" Padding="10" CornerRadius="0" Grid.ColumnSpan="7" Grid.Row="0">
<Label Text="Edit Mileage" HorizontalTextAlignment="Center" TextColor="White" FontSize="25" />
</Frame>
<DatePicker x:Name="sDate" Format="MM/dd/yyyy" Date="{Binding SDate}" BackgroundColor="Gray" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" TextColor="White"/>
<Label Text="{Binding EntError}" FontAttributes="Bold" TextColor="Yellow" FontSize="Small" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="6" />
<Label Text="Miles:" TextColor="White" FontSize="Small" Grid.Row="3" Grid.Column="0" Margin="9" />
<Entry Text="{Binding EntMiles}" Keyboard="Numeric" FontSize="Small" BackgroundColor="White" TextColor="Black" Grid.Row="3" Grid.Column="1" Margin="8" >
<Entry.Behaviors>
<Validate:MaxLengthValidator MaxLength="6"/>
<Validate:DecimalValidator />
</Entry.Behaviors>
</Entry>
<Label Text="Gas:" TextColor="White" FontSize="Small" Grid.Row="4" Grid.Column="0" Margin="12" Grid.ColumnSpan="2"/>
<Entry Text="{Binding EntGas}" Keyboard="Numeric" FontSize="Small" BackgroundColor="White" TextColor="Black" Grid.Row="4" Grid.Column="1" Margin="8" >
<Entry.Behaviors>
<Validate:MaxLengthValidator MaxLength="6"/>
<Validate:DecimalValidator />
</Entry.Behaviors>
</Entry>
<Label Text="Cost:" TextColor="White" FontSize="Small" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="3" Margin="9"/>
<Entry Text="{Binding EntCost}" Keyboard="Numeric" FontSize="Small" BackgroundColor="White" TextColor="Black" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2" Margin="8" >
<Entry.Behaviors>
<Validate:MaxLengthValidator MaxLength="7"/>
<Validate:DecimalValidator />
</Entry.Behaviors>
</Entry>
<Label Text="Note:" TextColor="White" FontSize="Small" Grid.Row="4" Grid.Column="2" Margin="10" Grid.ColumnSpan="2" HorizontalTextAlignment="Start"/>
<Entry Text="{Binding EntNote}" Keyboard="Default" FontSize="Small" BackgroundColor="White" TextColor="Black" Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="4" Margin="8">
<Entry.Behaviors>
<Validate:MaxLengthValidator MaxLength="20"/>
</Entry.Behaviors>
</Entry>
<Entry Text="{Binding EntId}" Grid.Row="4" Grid.Column="8" Grid.ColumnSpan="2" Margin="8" IsVisible="false"/>
<Button Command="{Binding Source={RelativeSource AncestorType={x:Type ViewModel:EditViewModel}}, Path=UpdateMileage}" CommandParameter="{Binding .}" IsEnabled="True" Text="Update" BackgroundColor="Yellow" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="1" TextColor="Black" Margin="4"/>
<Button Command="{Binding Source={RelativeSource AncestorType={x:Type ViewModel:EditViewModel}}, Path=Cancel}" CommandParameter="{Binding .}" Text="Cancel" BackgroundColor="Yellow" Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="2" TextColor="Black" Margin="4"/>
</Grid>
As for the question about the binding in the view code behind, I have this;
BindingContext = new EditViewModel();
I have a list with songs as items. A long press on the element should display a context menu.
AllSongsViewModel.xaml:
<DataTemplate x:Key="SongTemplate">
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Text="Edit" />
<MenuItem Text="Delete"/>
</ViewCell.ContextActions>
<StackLayout Padding="15,5" VerticalOptions="Center">
<Label Text="{Binding Title}"
FontSize="16"/>
<Label Text="{Binding Performer}"
FontSize="12"/>
</StackLayout>
</ViewCell>
</DataTemplate>
This works well, but I need to bind now so that the context menu opens depending on bool IsAdmin, which lies in AllSongsViewModel
AllSongsViewModel.cs:
public bool IsAdmin => _authService.LoggedUser.Role == "Admin";
But I don’t know how to bind this property to the context menu
Unfortunately you can't do this on your ViewModel. But you can set a BindingContextChange event on your View Cell and change it there like this:
XAML:
<DataTemplate x:Key="SongTemplate">
<ViewCell BindingContextChanged="OnBindingContextChanged">
<StackLayout Padding="15,5" VerticalOptions="Center">
<Label Text="{Binding Title}"
FontSize="16"/>
<Label Text="{Binding Performer}"
FontSize="12"/>
</StackLayout>
</ViewCell>
In your code behind:
private void OnBindingContextChanged(object sender, EventArgs e)
{
base.OnBindingContextChanged();
if (BindingContext == null)
return;
ViewCell theViewCell = ((ViewCell)sender);
var viewModel = this.BindingContext.DataContext as AllSongsViewModel;
theViewCell.ContextActions.Clear();
if (viewModel.IsAdmin)
{
theViewCell.ContextActions.Add(new MenuItem()
{
Text = "Delete",
});
theViewCell.ContextActions.Add(new MenuItem()
{
Text = "Edit",
});
}
}
Homepage showing products in a list according to the category selected.Initially showing products of first category. API response is null for first category but count is correct,showing only blank frames. After switching from other categories, products are shown correctly.Awaited the tasks. I think the problem is with async-await calls.Help need to rectify this..
private async Task InitializeAsync()
{
await Get_categories(); //calling method
}
public Task Initialization { get; private set; }
public Grid_vm() //constructor
{
Initialization = InitializeAsync();
}
public async Task Get_categories()
{
var items = await restClient.Get_categories();
Categorylist = new List<Category_value>();
foreach (Category_data cat in items.data)
{
Category_value category = new Category_value();
if (cat.category_id=="6")
{
category.category_id = cat.category_id;
category.category_name = cat.category_name;
Categorylist.Add(category);
}
else
{
category.category_id = cat.category_id;
category.category_name = cat.category_name;
Categorylist.Add(category);
}
}
await Get_branch_products("6") ; // calling first category
}
public async Task Get_branch_products (string category_id)
{
RestClient restClient = new RestClient();
var items=await restClient.Get_branch_products2(category_id);//calling restAPI
Productlist = new List<Product_Value2>();//var items null initially
foreach (Product_Data p in items.data)
{
Product_Value2 val = new Product_Value2();
val.available_qty = p.available_qty;
if (p.status == "1")
{
val.visible = true ;
OnPropertyChanged("visible");
val.visibility = false;
OnPropertyChanged("visibility");
Productlist.Add(val);
}
else
{
val.visible = true ;
OnPropertyChanged("visible");
val.visibility = false;
OnPropertyChanged("visibility");
val.opacity = 0.25;
OnPropertyChanged("opacity");
Productlist.Add(val);
}
}
}
}
public async Task<ProductDetails> Get_branch_products2(string cat_id)
{
var formcontent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>("category_id",cat_id)
});
var response = await client.PostAsync(base_url + "listbranchproduct", formcontent).ConfigureAwait(false);//execution returns null from here
var result = await response.Content.ReadAsStringAsync();//executed later
var status = JsonConvert.DeserializeObject<ProductDetails>(result);
return status;
}
<ListView x:Name="pdt_list" HasUnevenRows="True" SeparatorVisibility="None" ItemsSource="{Binding Productlist}" BackgroundColor="White" Margin="0,0,0,0">
<ListView.ItemTemplate>
<DataTemplate >
<ViewCell >
<ViewCell.View>
<Frame HasShadow="False" Margin=" 0,10,0,10" Padding="10,0,10,5" BackgroundColor="#f1f1f1" HeightRequest="80" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" >
<Grid Padding="0">
<!--<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" Margin="0,10,0,10" >-->
<StackLayout VerticalOptions="FillAndExpand" Margin="0" Padding="10,0,0,0" Orientation="Horizontal" Opacity="{Binding opacity}">
<Image Source="{Binding image}" Aspect="AspectFill" WidthRequest="70" HeightRequest="180" VerticalOptions="FillAndExpand" />
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical" >
<Label Text="{Binding Name}" Font="Bold" VerticalTextAlignment="Center" FontSize="Small" TextColor="Black" FontFamily="opensans_light.ttf#opensans_light" Margin="10,20,0,0" />
<StackLayout Orientation="Horizontal" Margin="10,0,0,0" HorizontalOptions="Start" VerticalOptions="Start" >
<Label Text="{Binding sellingprice_default}" Font="Bold" HorizontalOptions="Start" Margin="0" TextColor="#FA2E27" VerticalTextAlignment="Start" FontSize="Small" FontFamily="opensans_light.ttf#opensans_light" />
<Label Text="QAR" TextColor="#FA2E27" HeightRequest="90" FontSize="Small" HorizontalOptions="Start" VerticalTextAlignment="Start" VerticalOptions="FillAndExpand" />
</StackLayout>
</StackLayout>
<ImageButton Source="carts.png" BackgroundColor="Transparent" IsVisible="{Binding visible}" HorizontalOptions="EndAndExpand" WidthRequest="40" HeightRequest="40" VerticalOptions="CenterAndExpand" Clicked="Add_cart_Clicked" Margin="0,20,0,0" Aspect="AspectFit">
</ImageButton>
<StackLayout Orientation="Horizontal" BackgroundColor="Transparent" IsVisible="{Binding visibility}" HorizontalOptions="EndAndExpand">
<ImageButton Source="minus.png" HorizontalOptions="End" VerticalOptions="Center" Aspect="Fill" BackgroundColor="Transparent" WidthRequest="20" HeightRequest="20" Clicked="Minus_Tapped" />
<Label Text="{Binding Number2}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand" FontSize="Medium" TextColor="Black" FontFamily="opensans_light.ttf#opensans_light" Margin="0,0,0,0" />
<ImageButton Source="plus2.png" HorizontalOptions="End" Aspect="Fill" VerticalOptions="Center" BackgroundColor="Transparent" WidthRequest="20" HeightRequest="20" Clicked="Plus_Tapped" />
</StackLayout>
</StackLayout>
<StackLayout BackgroundColor="Black" HorizontalOptions="EndAndExpand" VerticalOptions="StartAndExpand" WidthRequest="100" HeightRequest="25" IsVisible="{Binding opaque}" Margin="0,0,0,0" >
<Label Text="Not Available" FontFamily="opensans_light.ttf#opensans_light" TextColor="White" FontAttributes="Bold" HorizontalOptions="Center" VerticalTextAlignment="Center" />
</StackLayout>
</Grid>
</Frame>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
opacity was provided inside the Get_branch_products (string category_id) method else block as 0.25.
val.opacity = 1;
OnPropertyChanged("opacity");
was not given inside if block adding it there solved the issue.
I have sample XAML with TextBox code as:
XAML
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Center"
Text="{Binding Path=Remarks, UpdateSourceTrigger=PropertyChanged}"
BorderThickness="0.5" Margin="0" Height="50" Background="Transparent" Foreground="White" />
<Button CommandParameter="{Binding ListExecActionId}"
Command="{Binding Source={StaticResource Locator}, Path=TaskPerformanceModel.ActivityAction_comment}"
Content="Save" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3,0,0,0" Height="Auto" />
View Model:
public string Remarks
{
get { return _remarks; }
set
{
if (!string.Equals(_remarks, value))
{
_remarks = value;
RaisePropertyChanged("Remarks");
}
}
}
ActivityAction_coment as follows
public RelayCommand<object> ActivityAction_comment
{
get
{
if (_ActivityAction_comment == null)
{
_ActivityAction_comment = new RelayCommand<object>((ExecActionId) => ActivityComment(ExecActionId));
}
return _ActivityAction_comment;
}
}
private void ActivityComment(object _id)
{
try
{
using (DataContext objDataContext = new DataContext(DBConnection.ConnectionString))
{
ListExecutionAction tblListExec = objDataContext.ListExecutionActions.Single(p => p.Id == Convert.ToInt32(_id));
**tblListExec.Remarks = Remarks; // Not getting Remarks value from Textbox**
objDataContext.SubmitChanges();
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message, "TaskExecution:ActivityComment");
}
}
I am unable to get textbox (Remarks) value in view model. Always getting "".
can any one help me out please.
For more clarity I am updating view:
<ListView.View>
<GridViewColumn >
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding ActionDescription}" Foreground="White" FontSize="16"></TextBlock>
<ToggleButton Name="button">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<TextBlock>Remarks!!</TextBlock>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Popup IsOpen="{Binding IsChecked, ElementName=button}" StaysOpen="False" Width="250" Height="100">
<StackPanel>
<TextBlock Background="LightBlue" Text="{Binding ActionDescription}"></TextBlock>
<TextBlock Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Comments:" Foreground="White" Background="Transparent" />
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Center"
Text="{Binding Path=Remarks, UpdateSourceTrigger=PropertyChanged}"
BorderThickness="0.5" Margin="0" Height="50"/>
<!--Text="{Binding Remarks, Mode=OneWayToSource}" Text="{Binding Path=Remarks, UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding CollectionOfListQueue}" Background="Transparent" Foreground="White"-->
<Button CommandParameter="{Binding ListExecActionId}" Command="{Binding Source={StaticResource Locator}, Path=TaskPerformanceModel.ActivityAction_comment}" Content="Save" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3,0,0,0" Height="Auto" />
<Button Content="Cancel" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="2,0,0,0" Height="Auto" />
<!--</Grid>-->
</StackPanel>
</Popup>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
Bind to ActivityAction_comment and Remarks properties of the view model:
<Button CommandParameter="{Binding ListExecActionId}"
Command="{Binding DataContext.ActivityAction_comment, RelativeSource={RelativeSource AncestorType=ListView}}"
Content="Save" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3,0,0,0" Height="Auto" />
You need to the same for the Remarks binding
<TextBox Text="{Binding DataContext.Remarks, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType=ListView}}" ... />
You should then be able to get the value in the TextBox using the Remarks source property:
private void ActivityComment(object _id)
{
try
{
using (DataContext objDataContext = new DataContext(DBConnection.ConnectionString))
{
ListExecutionAction tblListExec = objDataContext.ListExecutionActions.Single(p => p.Id == Convert.ToInt32(_id));
string remarks = Remarks;
objDataContext.SubmitChanges();
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message, "TaskExecution:ActivityComment");
}
}
After press, the return button on-screen keyboard the listview hide from the iOS screen. The same code is running perfectly on Android. I have create the 30 second video that will help you understand the problem.
The code file and Video can be download from here https://drive.google.com/drive/folders/1Q4O1KexIHvrCX79AR3CesRXJRWM1o2JR?usp=sharing
<ListView x:Name="listViewOrder" ItemTapped="OnActivitySelected" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame HasShadow="True" OutlineColor="Silver" Padding="3">
<Grid BackgroundColor="{Binding RowColour}" ColumnSpacing="2" Padding="2">
<StackLayout Orientation="Horizontal" HeightRequest="35" BackgroundColor="{Binding RowColour}" Padding="10">
<StackLayout Spacing="0" BackgroundColor="{Binding RowColour}" Orientation="Horizontal" HorizontalOptions="Start">
<Label FontSize="Medium" TextColor="#707070" Text="{Binding GFIELD3}" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
</StackLayout>
<StackLayout Spacing="0" BackgroundColor="{Binding RowColour}" Orientation="Horizontal" HorizontalOptions="EndAndExpand">
<Image Aspect="AspectFit" Source = "{Binding ImageStatus}" HorizontalOptions="StartAndExpand" VerticalOptions="Center" HeightRequest = "20" WidthRequest="20" />
</StackLayout>
</StackLayout>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout x:Name="layoutForBluetooth" HeightRequest="200" Padding="5, 5, 5, 5" BackgroundColor="#5DCBEE" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Frame Padding="5,5,5,5" HorizontalOptions="FillAndExpand" OutlineColor="Black" HasShadow="True">
<Grid>
<Label Text="Scan Your Barcode" x:Name="lblDriverNumber" TextColor="Black" FontSize="Medium" HorizontalOptions="FillAndExpand" Margin="0,10" />
<Entry x:Name="txtentry" FontSize="Medium" TextColor="Black" WidthRequest="400" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" />
</Grid>
</Frame>
async void Txtentry_Completed(object sender, EventArgs e)
{
BiendListview(orderID);
}
public void BiendListview(int OID)
{
try
{
List<GenericFields> GN = new List<GenericFields>();
GN = GetDeliveryOrderItems(OID);
if (GN != null)
{
// listViewOrder.BeginRefresh();
listViewOrder.ItemsSource = GN;
// listViewOrder.EndRefresh();
}
}
catch (Exception ex)
{
}
}
Please make a breakpoint to debug your GN's value. From your code:
if (GN != null)
{
// listViewOrder.BeginRefresh();
listViewOrder.ItemsSource = GN;
// listViewOrder.EndRefresh();
}
This if statement will always be true, since you have construct the GN by List<GenericFields> GN = new List<GenericFields>();. It will never be null.
You can try to modify it to:
if (GN.Count != 0)
{
// listViewOrder.BeginRefresh();
listViewOrder.ItemsSource = GN;
// listViewOrder.EndRefresh();
}