Hello developers!
I'm begginer in xamarin ,For some time i'm trying to implement a progress bar which will be increasing by tapping a image assing to it. My problem is that i can't figure out how to get access to Bindable property in my viewmodel. When i copied my model properties to viewmodel still no result, my dream solutions is that model's properties will stay in a model becouse i implement a observable object to this and create observable collection which is binded to listview in my page.xaml file. Can i ask you for some tips or guide my throught this step of my project ?
My code from ViewModel :
` public class SurfBoardViewModel : BaseViewModel
{
public ObservableRangeCollection Boards { get; }
public SurfBoardViewModel()
{
Boards = new ObservableRangeCollection<SurfBoard>
{
new SurfBoard()
{
Counter =0.2, Icon="icon.png"
},
new SurfBoard()
{
Counter= 0.1, Icon="icon.png"
},
new SurfBoard()
{
Counter =.8, Icon ="icon.png"
},
new SurfBoard()
{
Counter= .3, Icon="icon.png"
},
new SurfBoard()
{
Counter = 0.2, Icon="icon.png"
}
};
AddProgressCommand = new Command(AddProgress);
}
private void AddProgress()
{
}
public Command SetBusyCommand { get; }
public Command AddProgressCommand { get; }
//My last step was to copy property from model class and make it observable object to remain all functionality as it was but still no result
public class SurfBoard : ObservableObject
{
public SurfBoard()
{
}
double counter;
public double Counter
{
get { return counter; }
set
{
if (SetProperty(ref counter, value))
{
Debug.WriteLine("Counter changed");
}
}
}
string icon;
public string Icon
{
get { return icon; }
set
{
if (SetProperty(ref icon, value))
{
Debug.WriteLine("Icon Changed");
}
}
}
}`
Code from page xaml
`
<ListView x:Name="listView" ItemsSource="{Binding Boards}" HasUnevenRows="True"
Margin="10">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ProgressBar x:Name="progressBar"
Grid.Row="0" Grid.RowSpan="2"
Grid.Column="0"
Progress="{Binding Counter}"
/>
<Image x:Name="icon"
Grid.Row="0" Grid.RowSpan="2"
Grid.Column="1"
WidthRequest="60"
HeightRequest="60"
Source="{Binding Icon}"
>
<Image.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="2"
Command="{Binding AddProgressCommand}"/>
</Image.GestureRecognizers>
</Image>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>`