I have a custon renderer entry
public class EntryPerson: Entry
{
public int TestInt { get; private set; }
public EntryPerson(int TestInt)
{
this.TestInt = TestInt;
}
}
and in xaml in have this
<local:EntryPerson >
but i want to use so:
<local:EntryPerson TextInt="0" >
how pass untill to my render?
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
Check the following code
public class EntryPerson
{
public int TestInt { get; set; }
public EntryPerson()
{
}
public EntryPerson(int test)
{
TestInt = test;
}
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if(Control!=null)
{
var element = Element as EntryPerson;
var test = element.TestInt;
//Element.TextChanged += Element_TextChanged;
}
}
Related
I am not sure why this error is coming. Below My code:
Context:
public partial class AdminLoginEntities : DbContext
{
public AdminLoginEntities() : base("name=AdminLoginEntities"){ }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//throw new UnintentionalCodeFirstException();
modelBuilder.Entity<AdminLogin>().ToTable("AdminLogin");
}
public virtual DbSet<AdminLogin> AdminLogins { get; set; }
}
Controller Code:
AdminLoginEntities objadminE = new AdminLoginEntities();
[HttpPost]
[Route("AddAdmin")]
public IHttpActionResult InserNewAdmin(AdminLogin data)
{
if(!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
objadminE.AdminLogins.Add(data);
objadminE.SaveChanges();
}
catch(Exception)
{
throw;
}
return Ok(data);
}
I am having issues with binding context, after initialisation it doesn't update. so the button is not clickable and the name label doesn't update as its stated in ctor. This is the first and only page.
Page
<Label x:Name="NamesLabels" Text="{Binding Name}"/>
<Button HorizontalOptions="FillAndExpand" Text="Show scanner" Command="{Binding ShowScannerCommand}"/>
public MainPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = new MainPageViewModel();
}
//also tried
protected override void OnAppearing()
{
base.OnAppearing();
var context = new MainPageViewModel();
BindingContext = context;
name.Source = context.Name;
btn.Command = context.ShowScannerCommand;
}
ViewModel
public string Name
{
get => _name;
private set
{
_name = value;
NotifyPropertyChanged("Name");
}
}
public ICommand ShowScannerCommand { get; private set; }
public MainPageViewModel()
{
Name = "rwatag";
//have tried _name = "rwatag";
ShowScannerCommand = new Command(() => ShowScanner());
}
void ShowScanner()
{
System.Diagnostics.Debug.WriteLine("result");
}
this is what I get after clicking on button and when debugging the code doesn't get fired
[InputEventReceiver] Slow Input: took 118ms in dispatching, now at finishInputEvent (MotionEvent: event_seq=0, seq=78288, action=ACTION_DOWN)
Resolved pending breakpoint at '/Users/de/Projects/Demo/Demo/View/MainPage.xaml.cs:26,1' to void Demo.MainPage.OnAppearing () [0x00014].
[zygote] Do partial code cache collection, code=61KB, data=59KB
[zygote] After code cache collection, code=61KB, data=59KB
[zygote] Increasing code cache capacity to 256KB
I use your code and it works well on my side. I just add a string _name { get; set; } property and implement the INotifyPropertyChanged interface in MainPageViewModel.
Here is the code example:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = new MainPageViewModel();
}
}
public class MainPageViewModel : INotifyPropertyChanged
{
string _name { get; set; }
public string Name
{
get => _name;
private set
{
_name = value;
OnPropertyChanged("Name");
}
}
public ICommand ShowScannerCommand { get; private set; }
public MainPageViewModel()
{
Name = "rwatag";
ShowScannerCommand = new Command(() => ShowScanner());
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
void ShowScanner()
{
System.Diagnostics.Debug.WriteLine("result");
}
}
I have xamarin.forms app which contains a List view. I implemented a long press gesture for view cell of list view. Which works fine.What I am trying to do is, inside my list view there is a checkbox and its visibility property is set bind to data model. Defaultly it will be false. If I long pressed the view cell I want all checkbox to be visible.My purpose is multi select the list view.How can I accomplish that?
My data model
public class TimeSheetListData
{
public string StartDate { get; set; }
public string EndDate { get; set; }
public bool Selected { get; set; }
public bool IsCheckBoxVisible { get; set; }
}
I am simply setting the API data to the item source of listview.
ObservableCollection<TimeSheetListData> resultObjForApprovedTimeSheetList = new ObservableCollection<TimeSheetListData>();
After API call,
TimesheetListView.ItemsSource = resultObjForApprovedTimeSheetList;
My Longpress Event and changing the chekbox visiblility.
private void CustomView_LongPressEvent(object sender, EventArgs e)
{
foreach (TimeSheetListData TS in resultObjForApprovedTimeSheetList)
{
TSData.IsCheckBoxVisible = true;
}
TimesheetListView.ItemsSource = null;
TimesheetListView.ItemsSource = resultObjForApprovedTimeSheetList
}
It will change the visiblity of checkbox to true. But it will only visible when listview scrolled.
How can I solve this?
You need to implement INotifyPropertyChanged interface so that we could update the UI in runtime.
model
public class TimeSheetListData: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public string StartDate { get; set; }
public string EndDate { get; set; }
private bool selected;
public bool Selected {
get
{
return selected;
}
set
{
if (value!= null)
{
selected = value;
NotifyPropertyChanged("Selected");
}
}
}
private bool isCheckBoxVisible;
public bool IsCheckBoxVisible
{
get
{
return isCheckBoxVisible;
}
set
{
if (value != null)
{
isCheckBoxVisible = value;
NotifyPropertyChanged("IsCheckBoxVisible");
}
}
}
}
I am using SQLite to store data, I have a class:
class Customers
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[MaxLength(30)]
public string customerNumber { get; set; }
[MaxLength(100)]
public string customerName { get; set; }
}
How I am sending data is:
private void customer_Click(object sender, ItemClickEventArgs e)
{
Customers customer = e.ClickedItem as Customers;
if(customer != null)
{
Customers c = new Customers();
c.customerName = customer.customerName;
c.customerNumber = customer.customerNumber;
c.Id = customer.Id;
this.Frame.Navigate(typeof(customerDetail), c);
}
}
I need the data to display in text boxes on the detail page.
You need to access data on DetailsPage? Here you are:
public sealed partial class DetailPage : Page
{
public DetailPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Customers customer = (Customers)e.Parameter;
//Now you can get it from customer object
}
}
This is how I solved it:
From Page:
private void customer_Click(object sender, ItemClickEventArgs e)
{
Customers customer = e.ClickedItem as Customers;
if(customer != null)
{
Customers c = new Customers();
c.customerName = customer.customerName;
c.customerNumber = customer.customerNumber;
c.Id = customer.Id;
Frame.Navigate(typeof(customerDetail), c.Id.ToString());
}
}
To Page:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string custId = e.Parameter as string;
int custIDLookup = Convert.ToInt32(custId);
lookUp(custIDLookup);
navigationHelper.OnNavigatedTo(e);
}
I do this workflow with bookmark
namespace wwwfff
{
public sealed class CodeActivity3 : NativeActivity
{
public InArgument<string> EventName1
{ get; set; }
public OutArgument<string> Data1
{ get; set; }
protected override void Execute(NativeActivityContext context)
{
context.CreateBookmark(EventName1.Get(context), new BookmarkCallback(HandleEvent));
Console.WriteLine("Pppppppppppp");
}
private void HandleEvent(NativeActivityContext context, Bookmark bookmark, object obj)
{
if (obj != null)
{
Data1.Set(context, obj.ToString());
}
}
}
}
and i write in program
class Program
{
static void Main(string[] args)
{
WorkflowApplication wf = new WorkflowApplication(new Workflow1());
wf.Run();
wf.ResumeBookmark("C1", "Hello word");
}
}
but it doesn't type "ppppppp"
the workflow is only start ->CodeActivity3->writline()
thanks
you need probably override property in CodeActivity3 class
protected override bool CanInduceIdle { get { return true; } }