mvvm

How to Refresh the Bindings on HomePageViewModel when some data has been changed in Navigated Page2

眉间皱痕 提交于 2021-01-29 11:29:47
问题 I have some property which I am using from Page2 in HomePageViewModel, When I navigate to Page2 I have changed that property and on coming back by doing NavigiationPop. HomePage is not re-loaded/ refreshed at all as I have set the BindingContext in the constructor of HomePage, which is loaded only once. The solution which is working for me is Setting the BindingContext to the ViewModel on "onAppearing()", usually its not consider the best practice. But I also need to refresh the values which

Many instances of ViewModel, how to fix it?

大憨熊 提交于 2021-01-29 11:19:25
问题 I made ViewModelFactory by this example: public class ViewModelFactory extends ViewModelProvider.NewInstanceFactory { @SuppressLint("StaticFieldLeak") private static volatile ViewModelFactory INSTANCE; private final Application application; public static ViewModelFactory getInstance(Application application) { if (INSTANCE == null) { synchronized (ViewModelFactory.class) { if (INSTANCE == null) { INSTANCE = new ViewModelFactory(application); } } } return INSTANCE; } private ViewModelFactory

Populating ItemsControl Using Uniform Grid as ItemsPanel Column First

我只是一个虾纸丫 提交于 2021-01-29 10:02:57
问题 I have an ObservableCollection of 24 Things. private ObservableCollection<Thing> things; public ObservableCollection<Thing> Things { get => things; set { things= value; RaisePropertyChanged(); } } I also have a selected Thing private Thing selectedThing; public Thing SelectedThing { get => selectedThing; set { selectedThing= value; RaisePropertyChanged(); } } I need to display these items in a grid. I am creating a grid of buttons, each with a command and a command parameter that allows me to

Capturing and updating an image source using MVVM in Xamarin

可紊 提交于 2021-01-29 09:50:55
问题 I'm trying to capture photo and display the captured image in Xamarin but changing the image source binding just doesn't seem to work. This seems really simple so I'm not quite sure where I'm going wrong. MainPageViewModel.cs public class MainPageViewModel : ViewModelBase { private string _imageSource; public string ImageSource { get { return _imageSource; } set { _imageSource = value; SetProperty(ref _imageSource, value); } } public DelegateCommand TakePhotoCommand { get; private set; }

Problems with Bindings in Xamarin Forms (MVVM)

喜夏-厌秋 提交于 2021-01-29 08:45:12
问题 I am having some problems understanding xaml with mvvm. Sometimes works but others doesn't. ViewModel (implements INotifyPropertyChanged): private Class1 firstClass; public Class1 FirstClass{ get{return firstClass;} set{firstClass = value; OnPropertyChanged();} } private string name; public string Name{ get{return name;} set{name = value; OnPropertyChanged();} } private string address; public string Address{ get{return address;} set{address = value; OnPropertyChanged();} } View: private

CS0201 error in ICommand impmentation for WPF application

混江龙づ霸主 提交于 2021-01-29 08:27:15
问题 I develop a WPF application, obviously, I use MVVM pattern. Without an external library (MvvmCross, MvvmLight, ...) And I've tried to implement ICommand : Option 1 public class Command : ICommand { private readonly Func<bool> _canExecute; private readonly Action _action; public Command1(Action action, Func<bool> canExecute) { _action = action; _canExecute = canExecute; } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager

WPF: Binding Margin/Thickness Left and Top Property

泄露秘密 提交于 2021-01-29 08:01:08
问题 I got a problem with bindings(i know why am i becoming this exception but dunno how to solve the problem). I have tried this piece of code. <TextBlock HorizontalAlignment="Left" > <TextBlock.Margin> <Thickness Left="{Binding POSX.Value, Converter={StaticResource DPIConverter}}" Top="{Binding POSY.Value, Converter={StaticResource DPIConverter}}"/> </TextBlock.Margin> </TextBlock> Im getting an exception where it says that, u cant bind thickness [LEFT], [TOP] properties. (ik why : cause those

Include Dynamic Custom Xamarin Xaml View Control

南楼画角 提交于 2021-01-29 07:22:41
问题 Hello I have a repeating carousel I've copied for each deparment that I want to consolidate and make into a custom xaml view control. Here is the original carousel view I have copied several times in my page. I want to figure out how to clean this up with something externally from the page. <StackLayout Padding="10"> <Label Text="Human Resources" FontSize="Large" TextColor="#000000"></Label> <CarouselView ItemsSource="{Binding HumanResourcesCollection}" PeekAreaInsets="75" IndicatorView=

Cannot create an instance of class ViewModel in Android MVVM

喜你入骨 提交于 2021-01-29 04:53:55
问题 I am learning android MVVM pattern android development. I wanted to create a recycclerview activity to show data from server. But it's not accepting my viewmodel class. Bellow is my logcat errors. LOGCAT 2020-04-12 21:03:18.026 2008-2008/com.shovon.mvvm E/AndroidRuntime: FATAL EXCEPTION: main Process: com.shovon.mvvm, PID: 2008 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shovon.mvvm/com.shovon.mvvm.activity.RecyclerActivity}: java.lang.RuntimeException: Cannot

Cannot create an instance of class ViewModel in Android MVVM

眉间皱痕 提交于 2021-01-29 04:53:53
问题 I am learning android MVVM pattern android development. I wanted to create a recycclerview activity to show data from server. But it's not accepting my viewmodel class. Bellow is my logcat errors. LOGCAT 2020-04-12 21:03:18.026 2008-2008/com.shovon.mvvm E/AndroidRuntime: FATAL EXCEPTION: main Process: com.shovon.mvvm, PID: 2008 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shovon.mvvm/com.shovon.mvvm.activity.RecyclerActivity}: java.lang.RuntimeException: Cannot