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");
}
}
Related
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 have model:
public class Department
{
public int DepartmentID { get; set; }
[Required]
[UniqueDepartmentName]
public string Name { get; set; }
public List<Person> Persons { get; set; }
}
And DBcontext:
public class InstituteContext : DbContext
{
public InstituteContext (DbContextOptions<InstituteContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Department>().HasIndex(p => p.Name).IsUnique();
}
public DbSet<Institute.Models.Department> Department { get; set; }
}
As you see property "NAME" i make unique.
For validation i create My validation Attribute:
public class UniqueDepartmentName : ValidationAttribute
{
public override bool IsValid(object value)
{
var db = new InstituteContext();
}
}
But i can not create instance of InstituteContext, because constructor need parameters.
How i can create instance of InstituteContext? Or what should i pass to constructor in parameters?
Try this:
public class UniqueDepartmentName : ValidationAttribute
{
public override bool IsValid(object value)
{
var connectionString = "Your ConnectionString"
var options = new DbContextOptionsBuilder<InstituteContext>()
.UseSqlServer(new SqlConnection(connectionString)).Options;
using (var dbContext = new BloggingContext(options))
{
// Do necessary staffs here with dbContext
}
}
}
Your DbContextOptions method is in the wrong place, your constructor can be empty, and you need to add the method OnConfiguring, which receives the DbContextOptions.
Something like:
public DbSet<Department> Department { get; private set; }
protected override void OnConfiguring(DbContextOptionsBuilder options) {
// In my case I'm passing the connection string in this method below
options.UseSqlServer("Data Source=DATABASEIP;Initial Catalog=DATABASETABLE;" +
"User ID=USER;Password=PASSWORD");
}
I have an problem with Firebase!, I've created register and login page and works fine!. but i have an problem. why my button create a new 'child'?
How can i put button 'onClick' on same UID from identify users by button clicks ? What I want to do, I don't know how firebase works 100% can anyone explain for me? i really need to {get} does click buttons for identify every user on database. My page button
MainActivity
public class MainActivity extends AppCompatActivity {
private Button influenciador;
private Button marca;
private DatabaseReference mDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
influenciador = (Button) findViewById(R.id.BotaoSouInfluenciador);
marca = (Button) findViewById(R.id.BotaoSouMarca);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Usuários");
influenciador.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDatabase.child("Usuários").push().setValue("Pizza");
openDIContrato();
}
});
marca.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDatabase.child("Usuários").setValue("Burger");
openMarcaContrato();
}
});
}
public void openDIContrato() {
Intent intent = new Intent(this, DIContrato.class);
startActivity(intent);
}
public void openMarcaContrato() {
Intent intent = new Intent(this, MarcaContrato.class);
startActivity(intent);
}
}
Users class
public class Usuarios {
private String id;
private String email;
private String aniversario;
private String senha;
private String nome;
private String sexo;
public Usuarios() {
}
public void salvar(){
DatabaseReference referenciaFirebase = ConfiguracaoFirebase.getFirebase();
referenciaFirebase.child("Usuários").child(String.valueOf(getId())).setValue(this);
}
#Exclude
public Map<String, Object> toMap(){
HashMap<String, Object> hashMapUsuario = new HashMap<>();
hashMapUsuario.put("id", getId());
hashMapUsuario.put("email", getEmail());
hashMapUsuario.put("aniversario", getAniversario());
hashMapUsuario.put("nome", getnome());
hashMapUsuario.put("sexo", getSexo());
return hashMapUsuario;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getnome() {
return nome;
}
public void setnome(String nome) {
this.nome = nome;
}
public String getAniversario() {
return aniversario;
}
public void setAniversario(String aniversario) {
this.aniversario = aniversario;
}
public String getSexo() {
return sexo;
}
public void setSexo(String sexo) {
this.sexo = sexo;
}
}
You're not using the correct reference to your database. From the image with title "what I want to do", you can do so with this piece of code:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Usuários");
ref.child(iD).child("Button").setValue("Pizza");
//id is the string I can see in the databse image dG9ue...
I am new in Fluent NHibernet and i am using Fluent NHibernet in my asp.net application
this is my Poco class
public virtual int CategoryId { get; set; }
public virtual string CategoryName { get; set; }
public virtual bool IsActive { get; set; }
public virtual bool IsDeleted { get; set; }
My Mapping Class
public class clsCategoryMap : ClassMap<clsCategory>
{
public clsCategoryMap()
{
Id(x => x.CategoryId).Column("CategoryId").GeneratedBy.Assigned().Not.Nullable();
Map(x => x.CategoryName).Column("CategoryName").Not.Nullable();
Map(x => x.IsActive).Column("IsActive").Not.Nullable();
Map(x => x.IsDeleted).Column("IsDeleted").Not.Nullable();
Table("tblCategory");
}
}
Poco class and Mapping class both saprated in class Liberar like: DAL for Poco class and BLL For Mapping class.
And i create helper class it's below:
public class FNHelper
{
private static ISessionFactory _sessionfactory;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionfactory == null) { InitializationSessionFactory(); }
return _sessionfactory;
}
}
private static void InitializationSessionFactory()
{
_sessionfactory = Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2008
.ConnectionString(#"Server=test\SQLEXPRESS;Database=TestDB;User ID=sa;Password=root;")
.DefaultSchema("dbo")
.ShowSql()
)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<clsCategory>())
.ExposeConfiguration((cfg => new SchemaUpdate(cfg).Execute(true, true)))
.BuildSessionFactory();
}
public static ISession OpenSession()
{
return SessionFactory.OpenSession();
}
private static void BuildSchema(NHibernate.Cfg.Configuration configuration)
{
String SqliteRefFileName = #"D:\Projects\MeshpsDB.sql";
if (File.Exists(SqliteRefFileName))
File.Delete(SqliteRefFileName);
new SchemaExport(configuration)
.Create(true, true);
}
}
And finally i am doing in my form it's below:
protected void btnSave_Click(object sender, EventArgs e)
{
using (var session = FNHelper.OpenSession())
{
using (var tranction = session.Transaction)
{
var objCategory = new clsCategory
{
CategoryId = 0,
CategoryName = txtName.Text.Trim(),
IsActive = true,
IsDeleted = false
};
session.Save(objCategory);
tranction.Commit();
}
}
}
when i click on button then i am getting
so every one please tell me how can i solve this issue.
change m.FluentMappings.AddFromAssemblyOf<clsCategory>() to m.FluentMappings.AddFromAssemblyOf<clsCategoryMap>() because its the mappingss you want to add and these reside in another assembly.
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; } }