Changing Property in code behind does not update view - xamarin.forms

When I change my property which is a model object, The view does not update unless I reassign the binding context. I am not using mvvm, so no view model.
public partial class MainPage : ContentPage
{
private MySource _myCurrentSource = new MySource("yolor");
public MySource MyCurrentSource {
get { return _myCurrentSource; }
set {_myCurrentSource = value; }
}
public MainPage()
{
InitializeComponent();
MyCurrentSource = _myCurrentSource;
MainStack.BindingContext = MyCurrentSource;
label.SetBinding(Label.TextProperty, new Binding("SourceString"));
}
private void Button_Clicked(object sender, EventArgs e)
{
MyCurrentSource = new MySource("new string");
//property changed
MainStack.BindingContext = MyCurrentSource;
}
}
I want to get rid of : MainStack.BindingContext = MyCurrentSource;
This is what my xaml looks like
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DataBindingPlayGround.MainPage">
<StackLayout Padding="10, 0" x:Name="MainStack" HorizontalOptions="Center"
VerticalOptions="CenterAndExpand">
<Label x:Name="label" Text="TEXT" FontSize="48" />
<Button Text="Change" Clicked="Button_Clicked"/>
</StackLayout>
</ContentPage>
Model class:
public class MySource
{
public MySource(string str)
{
SourceString = str;
}
public string SourceString { get; set; }
}

Modify MySource class as follows to have a try:
public class MySource : INotifyPropertyChanged
{
public MySource(string str)
{
sourceString = str;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string sourceString;
public double SourceString
{
set
{
if (sourceString != value)
{
sourceString = value;
OnPropertyChanged("SourceString");
}
}
get
{
return sourceString;
}
}
}
=============================Update=================================
Although not understanding the logic of your application, if you want to make MyCurrentSource works. You will also need to use INotifyPropertyChanged:
public partial class MainPage : ContentPage ,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private MySource _myCurrentSource;
public MySource MyCurrentSource
{
set
{
if (_myCurrentSource != value)
{
_myCurrentSource = value;
OnPropertyChanged("MyCurrentSource");
}
}
get
{
return _myCurrentSource;
}
}
public MainPage()
{
InitializeComponent();
_myCurrentSource = new MySource("yolor");
//MyCurrentSource = _myCurrentSource;
MainStack.BindingContext = _myCurrentSource ;
label.SetBinding(Label.TextProperty, new Binding("SourceString"));
}
private void Button_Clicked(object sender, EventArgs e)
{
_myCurrentSource = new MySource("new string");
//property changed
MainStack.BindingContext = _myCurrentSource;
}
}
Or you can directly set new Model when BindingContext.
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MainStack.BindingContext = new MySource("yolor");
label.SetBinding(Label.TextProperty, new Binding("SourceString"));
}
private void Button_Clicked(object sender, EventArgs e)
{
//property changed
MainStack.BindingContext = new MySource("new string");
}
}

This is finally what worked for me, in case anyone has similar situation:
Source classes below:
public class FirstSource
{
public string sourceString;
public string SourceString { get; set; }
public int SourceOneProp2 { get; set; }
public FirstSource(string str, int num)
{
SourceString = str;
SourceOneProp2 = num;
}
}
public class SecondSource
{
public string ExampleField { get; set; }
public int SourceTwoProp2 { get; set; }
public SecondSource(string exampleField, int num)
{
ExampleField = exampleField;
SourceTwoProp2 = num;
}
}
ViewModel (Decided to use to make task easier)
class MainPageViewModel : BaseViewModel
{
private FirstSource _sourceOne;
private SecondSource _sourceTwo;
public FirstSource SourceOne
{
get { return _sourceOne; }
set { SetValue(ref _sourceOne, value); }
}
public SecondSource SourceTwo
{
get { return _sourceTwo; }
set { SetValue(ref _sourceTwo, value); }
}
}
Code Behind:
public partial class MainPage : ContentPage
{
int counter = 0;
private MainPageViewModel ViewModel
{
get { return BindingContext as MainPageViewModel; }
set { BindingContext = value; }
}
public MainPage()
{
InitializeComponent();
ViewModel = new MainPageViewModel();
ViewModel.SourceOne = new FirstSource("init1", 10);
ViewModel.SourceTwo = new SecondSource("init2", 20);
}
private void Button_Clicked(object sender, EventArgs e)
{
counter += 1;
ViewModel.SourceOne = new FirstSource("Changed1", 100+counter);
}
private void Button_Clicked_1(object sender, EventArgs e)
{
counter += 1;
ViewModel.SourceTwo = new SecondSource("Changed2", 200+counter);
}
}
XAML/UI
<StackLayout Padding="10, 0" x:Name="MainStack" HorizontalOptions="Center" VerticalOptions="Start">
<Label x:Name="label" Text="{Binding Path=SourceOne.SourceString}" FontSize="48" />
<Label Text="{Binding Path=SourceOne.SourceOneProp2}" />
<Button Text="Change" Clicked="Button_Clicked"/>
<StackLayout Padding="10, 0" x:Name="SecondStack">
<Label x:Name="secondLabel" Text="{Binding Path=SourceTwo.ExampleField}" FontSize="48" />
<Label Text="{Binding Path=SourceTwo.SourceTwoProp2}" />
<Button Text="Change" Clicked="Button_Clicked_1"/>
</StackLayout>
</StackLayout>

Related

Image with rounded corners

I am trying to get an image in the shape of rectangle with rounded Cornes. I have tried to use nugget fftransformations and frame. So far I am not getting the result I want. Using the nugget turns the image into square no matter what size I give to it. Using frame for some reason doesn't actually round the corners. enter image description here
<StackLayout VerticalOptions="CenterAndExpand">
<ffimageloading:CachedImage VerticalOptions="CenterAndExpand"
WidthRequest="530" HeightRequest="334"
DownsampleToViewSize="true"
Source = "http://loremflickr.com/530/334/nature?filename=simple.jpg">
<ffimageloading:CachedImage.Transformations>
<fftransformations:RoundedTransformation Radius="10"/>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
<ffimageloading:CachedImage VerticalOptions="CenterAndExpand"
WidthRequest="530" HeightRequest="334"
DownsampleToViewSize="true"
Source = "http://loremflickr.com/530/334/nature?filename=simple.jpg">
<ffimageloading:CachedImage.Transformations>
<fftransformations:CornersTransformation CornersTransformType="AllRounded"/>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
<Grid VerticalOptions="CenterAndExpand">
<Frame Padding="0" WidthRequest="530" HeightRequest="334"
HorizontalOptions="Center"
VerticalOptions="Center" CornerRadius="20" >
<Image Source = "http://loremflickr.com/530/330/nature?filename=simple.jpg" Aspect="AspectFill" />
</Frame>
</Grid>
</StackLayout>
Some time ago I needed corner effects on other controls. And it applies to image too.
All you need is to create Effect:
public class RoundCornersEffect : RoutingEffect
{
public RoundCornersEffect() : base($"MySuperApp.{nameof(RoundCornersEffect)}")
{
}
public static readonly BindableProperty CornerRadiusProperty =
BindableProperty.CreateAttached(
"CornerRadius",
typeof(int),
typeof(RoundCornersEffect),
0,
propertyChanged: OnCornerRadiusChanged);
public static int GetCornerRadius(BindableObject view) =>
(int)view.GetValue(CornerRadiusProperty);
public static void SetCornerRadius(BindableObject view, int value) =>
view.SetValue(CornerRadiusProperty, value);
private static void OnCornerRadiusChanged(BindableObject bindable, object oldValue, object newValue)
{
if (!(bindable is View view))
return;
var cornerRadius = (int)newValue;
var effect = view.Effects.OfType<RoundCornersEffect>().FirstOrDefault();
if (cornerRadius > 0 && effect == null)
view.Effects.Add(new RoundCornersEffect());
if (cornerRadius == 0 && effect != null)
view.Effects.Remove(effect);
}
}
And implement it on both platforms:
IOS:
public class RoundCornersEffectIOS : PlatformEffect
{
protected override void OnAttached()
{
try
{
PrepareContainer();
SetCornerRadius();
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
protected override void OnDetached()
{
try
{
Container.Layer.CornerRadius = new nfloat(0);
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
{
if (args.PropertyName == RoundCornersEffect.CornerRadiusProperty.PropertyName)
SetCornerRadius();
}
private void PrepareContainer()
{
Container.ClipsToBounds = true;
Container.Layer.AllowsEdgeAntialiasing = true;
Container.Layer.EdgeAntialiasingMask = CAEdgeAntialiasingMask.All;
}
private void SetCornerRadius()
{
var cornerRadius = RoundCornersEffect.GetCornerRadius(Element);
Container.Layer.CornerRadius = new nfloat(cornerRadius);
}
}
Droid:
public class RoundCornersEffectDroid : PlatformEffect
{
private Android.Views.View View => Control ?? Container;
protected override void OnAttached()
{
try
{
PrepareContainer();
SetCornerRadius();
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
protected override void OnDetached()
{
try
{
View.OutlineProvider = ViewOutlineProvider.Background;
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
{
if (args.PropertyName == RoundCornersEffect.CornerRadiusProperty.PropertyName)
SetCornerRadius();
}
private void PrepareContainer()
{
View.ClipToOutline = true;
}
private void SetCornerRadius()
{
var cornerRadius = RoundCornersEffect.GetCornerRadius(Element) * GetDensity();
View.OutlineProvider = new RoundedOutlineProvider(cornerRadius);
}
private static double GetDensity() =>
DeviceDisplay.MainDisplayInfo.Density;
private class RoundedOutlineProvider : ViewOutlineProvider
{
private readonly double _radius;
public RoundedOutlineProvider(double radius)
{
_radius = radius;
}
public override void GetOutline(Android.Views.View view, Outline outline)
{
outline?.SetRoundRect(0, 0, view.Width, view.Height, (float)_radius);
}
}
}
Then you can use it in control:
<Image Source="mylogo.png" VerticalOptions="Center" Aspect="AspectFit" myeffects:RoundCornersEffect.CornerRadius="5"/>

Always keep on keyboard in android on focus to next Entry

I am having 20 entries and these are created dynamically through loop. and on textchanges i have set focus to the next entry ,having focus to next entry keyboard hides and than show again and it happen on every text change.I want that keyboard should not hide every time after textchange it show always show till the last 20th entry..
----My Custom Entry
public class MyEntry : Entry
{
public static readonly BindableProperty IsFocusProperty = BindableProperty.Create("IsFocus", typeof(bool), typeof(MyEntry), false, propertyChanged: OnChanged);
static void OnChanged(BindableObject bindable, object oldValue, object newValue)
{
var entry = bindable as MyEntry;
var focus = (bool)newValue;
if (focus)
{
entry.Focus();
}
else
{
entry.Unfocus();
}
}
public bool IsFocus
{
get { return (bool)GetValue(IsFocusProperty); }
set
{
SetValue(IsFocusProperty, value);
}
}
public MyEntry()
{
this.Focused += MyEntry_Focused;
this.Unfocused += MyEntry_Unfocused;
}
private void MyEntry_Unfocused(object sender, FocusEventArgs e)
{
this.IsFocus = false;
}
private void MyEntry_Focused(object sender, FocusEventArgs e)
{
this.IsFocus = true;
}
}
--My model
public class CrossingUIModel : BaseViewModel
{
public int Id { get; set; }
private string fieldValue;
public string FieldValue
{
get { return fieldValue; }
set
{
if (fieldValue != value)
{
fieldValue = value;
OnPropertyChanged(nameof(FieldValue));
}
}
}
private bool isFocus = false;
public bool IsFocus
{
get { return isFocus; }
set
{
if (isFocus != value)
{
isFocus = value;
OnPropertyChanged(nameof(IsFocus));
}
}
}
}
--my View Model
public void CreateUI()
{
UserDialogs.Instance.ShowLoading();
BindCrossingUIModel = new ObservableCollection<CrossingUIModel>();
for (int i = 1; i < 21; i++)
{
CrossingUIModel model = new CrossingUIModel();
model.Id = i;
BindCrossingUIModel.Add(model);
}
foreach (CrossingUIModel model in BindCrossingUIModel)
{
model.PropertyChanged += Model_PropertyChanged;
}
UserDialogs.Instance.HideLoading();
}
private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "FieldValue")
{
var model = sender as CrossingUIModel;
if (model.FieldValue.Length == 1)
{
model.FieldValue = model.FieldValue.Substring(0, 1);
model.IsFocus = false;
int id = model.Id;
if (id == 20)
{
var FocusControl = _page.FindByName<Entry>("Amt");
if (FocusControl != null)
{
FocusControl.Focus();
}
}
else
{
BindCrossingUIModel[id].IsFocus = true;
}
}
}
}
--xaml file
<CollectionView.ItemTemplate>
<DataTemplate>
<!--<StackLayout HorizontalOptions="FillAndExpand">
<Entry x:Name="Fields" Text="{Binding FieldValue, Mode=TwoWay}"
ReturnType="Next" MaxLength="1" Keyboard="Numeric"
TextChanged="Fields_TextChanged" ></Entry>
</StackLayout>-->
<StackLayout WidthRequest="100" HorizontalOptions="FillAndExpand" >
<local:MyEntry WidthRequest="80" BackgroundColor="White" HeightRequest="50"
x:Name="Fields" Text="{Binding FieldValue, Mode=TwoWay}"
IsFocus="{Binding IsFocus, Mode=TwoWay}"
ReturnType="Next" Keyboard="Numeric" MaxLength="1"
></local:MyEntry>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
You could modify the code by removing the line model.IsFocus = false;
private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "FieldValue")
{
var model = sender as CrossingUIModel;
if (model.FieldValue.Length == 1)
{
model.FieldValue = model.FieldValue.Substring(0, 1);
int id = model.Id;
if (id == 20)
{
var FocusControl = _page.FindByName<Entry>("Amt");
if (FocusControl != null)
{
FocusControl.Focus();
}
}
else
{
BindCrossingUIModel[id].IsFocus = true;
}
}
}

Could not change the property value dynamically in button click

I have created bindable property called Text in TargetClass.cs. That Text property is nested bindable property.
TargetClass.cs :
public class TargetClass : BindableObject
{
public static readonly BindableProperty TextProperty =
BindableProperty.Create("Text", typeof(string), typeof(TargetClass), "Default", BindingMode.TwoWay, null,
OnTextChanged);
private static void OnTextChanged(BindableObject bindable, object oldValue, object newValue)
{
}
public string Text
{
get
{
return (string)GetValue(TextProperty);
}
set
{
SetValue(TextProperty, value);
}
}
}
ViewModel.cs :
public class ViewModel : INotifyPropertyChanged
{
private string m_text = "New Value";
public string TextValue
{
get { return m_text; }
set
{
m_text = value;
OnPropertyChanged("TextValue");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Then I have created MyView.cs
public class MyView : ContentView
{
private TargetClass target;
Label label;
public TargetClass Target
{
get
{
return target;
}
set
{
target = value;
label.Text = target.Text;
}
}
public MyView()
{
label = new Label();
label.FontSize = 50;
Content = label;
}
}
MainPage.xaml :
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:BindingDemo"
x:Class="BindingDemo.MainPage">
<StackLayout>
<local:MyView >
<local:MyView.Target>
<local:TargetClass Text="{Binding TextValue}" >
<local:TargetClass.BindingContext>
<local:ViewModel />
</local:TargetClass.BindingContext>
</local:TargetClass>
</local:MyView.Target>
</local:MyView>
<Button Text="Click" Clicked="Button_Clicked" />
</StackLayout>
MainPage.xaml.cs:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
(BindingContext as ViewModel).TextValue = "Latest Value";
}
}
TextValue property is binded with Text bindble property.
I have changed value of TextValue property in button click in MainPage.xaml.cs.
If I click the button. it should show Latest value. But it shows new value,it did not changed from new value to latest value.
Is it possible to change the value of TextValue property in Button click dynamically ?
If you want to use the method above,you could check below (But it's not recommended.If TargetClass is not used anywhere else, this class seems redundant, you can add a BindableProperty to MyView directly):
in TargetClass.cs:
public class TargetClass : BindableObject
{
public static readonly BindableProperty TextProperty =
BindableProperty.Create("Text", typeof(string), typeof(TargetClass), "Default", BindingMode.TwoWay, propertyChanged: OnTextChanged);
private static void OnTextChanged(BindableObject bindable, object oldValue, object newValue)
{
((TargetClass)bindable).View.label.Text = (string)newValue;
}
public string Text
{
get
{
return (string)GetValue(TextProperty);
}
set
{
SetValue(TextProperty, value);
}
}
public static readonly BindableProperty ViewProperty =
BindableProperty.Create("View", typeof(MyView), typeof(TargetClass), null, BindingMode.TwoWay);
public MyView View
{
get
{
return (MyView)GetValue(ViewProperty);
}
set
{
SetValue(ViewProperty, value);
}
}
}
in the page.xaml:
<StackLayout >
<local:MyView x:Name="MyView">
<local:MyView.Target>
<local:TargetClass x:Name="MyClass" View="{Binding ., Source={x:Reference MyView}}" Text="{Binding TextValue}" >
<local:TargetClass.BindingContext>
<local:ViewModel />
</local:TargetClass.BindingContext>
</local:TargetClass>
</local:MyView.Target>
</local:MyView>
<Button Text="Click" Clicked="Button_Clicked" />
</StackLayout>
in page.xaml.cs:
private void Button_Clicked(object sender, EventArgs e)
{
(MyClass.BindingContext as ViewModel).TextValue = "Latest Value";
}

how to Add “View More” and view less at the end of label after 3 lines

I have label with 10 lines of data in it but need to show only 3 line after that need to add view more button and after expanding view less , how to add it in xamarin form
According to your description, you can use custom control to do this.
Firstly, you need to create contentview, name LargeTextLabel.xaml.
<ContentView.Content>
<StackLayout Orientation="Vertical">
<Label
x:Name="SmallLabel"
BackgroundColor="Beige"
HeightRequest="50"
IsVisible="true" />
<Label
x:Name="FullLabel"
BackgroundColor="BurlyWood"
HeightRequest="200"
IsVisible="false" />
<Button x:Name="ExpandContractButton" Text="See More" />
</StackLayout>
</ContentView.Content>
Then create BindableProperty by code behind.
public partial class LargeTextLabel : ContentView
{
public LargeTextLabel ()
{
InitializeComponent ();
}
public static readonly BindableProperty ExpandedProperty = BindableProperty.Create(
nameof(LargeTextLabel),
typeof(bool),
typeof(ContentView),
false,
BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) =>
{
if (newValue != null && bindable is LargeTextLabel control)
{
var actualNewValue = (bool)newValue;
control.SmallLabel.IsVisible = !actualNewValue;
control.FullLabel.IsVisible = actualNewValue;
control.ExpandContractButton.Text = actualNewValue ? "See Less" : "See More";
}
});
public bool Expanded { get; set; }
public static readonly BindableProperty TextProperty = BindableProperty.Create(
nameof(LargeTextLabel),
typeof(string),
typeof(ContentView),
default(string),
BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) =>
{
if (newValue != null && bindable is LargeTextLabel control)
{
var actualNewValue = (string)newValue;
control.SmallLabel.Text = actualNewValue;
control.FullLabel.Text = actualNewValue;
}
});
public string Text { get; set; }
public static readonly BindableProperty CommandProperty = BindableProperty.Create(
nameof(LargeTextLabel),
typeof(ICommand),
typeof(ContentView),
default(Command),
BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) =>
{
if (newValue != null && bindable is LargeTextLabel control)
{
var actualNewValue = (ICommand)newValue;
control.ExpandContractButton.Command = actualNewValue;
}
});
public ICommand Command { get; set; }
}
Now, you can use this custom control in your page.
<ContentPage.Content>
<StackLayout>
<local:LargeTextLabel
Command="{Binding ExpandContractCommand}"
Expanded="{Binding TextExpanded}"
Text="{Binding LabelText}" />
</StackLayout>
</ContentPage.Content>
Create some property to bind this custom control, please implement INotifyPropertychanged to notify value update.
public partial class Page3 : ContentPage, INotifyPropertyChanged
{
private string _LabelText;
public string LabelText
{
get { return _LabelText; }
set
{
_LabelText = value;
RaisePropertyChanged("LabelText");
}
}
private ICommand _ExpandContractCommand;
private bool _TextExpanded;
public bool TextExpanded
{
get { return _TextExpanded; }
set
{
_TextExpanded = value;
RaisePropertyChanged("TextExpanded");
}
}
public Page3 ()
{
InitializeComponent ();
LabelText = "Can any one help me on this?\nI want set read more option for multiline text end of label when i click on that read more it will expand or navigate to the any other page. Please help me on this .\n\nThanks in advance.";
this.BindingContext = this;
}
public ICommand ExpandContractCommand
{
get
{
if (_ExpandContractCommand == null)
{
_ExpandContractCommand = new Command(() => {
TextExpanded = !TextExpanded;
});
}
return _ExpandContractCommand;
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

Showing Empty Screen in FlowListView in Xaml Xamarin.Forms

How to do FlowListView in XAML Xamarin.Forms?
Here is my Code:
XAML:
<flv:FlowListView FlowColumnCount="3" SeparatorVisibility="None" HasUnevenRows="true" x:Name="grid_list" ItemsSource="{Binding list_grid}" HeightRequest="100" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate>
<Image Source="{Binding Image}" Margin="20" VerticalOptions="Fill" HorizontalOptions="Fill" XAlign="Center" YAlign="Center"/>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
CODE.cs
public partial class PlanCampaign_DetailPage : ContentPage
{
ObservableCollection<CarosualImages> list_grid { get; set; }
public PlanCampaign_DetailPage()
{
InitializeComponent();
this.BindingContext = this;
list_grid = new ObservableCollection<CarosualImages>()
{
new CarosualImages { Image="maharastra.jpg"},
new CarosualImages {Image="delhi.jpg"},
new CarosualImages {Image="delhi.jpg"},
new CarosualImages {Image="delhi.jpg"},
new CarosualImages {Image="delhi.jpg"},
};
grid_list.ItemsSource = list_grid;
}
ModelClass:
public class CarosualImages
{
public string Image { get; set; }
}
Could anyone tell that where i did mistake here, this is showing Empty Screen.
Here is the code for INotifyPropertyChanged
public class CarosualImages : INotifyPropertyChanged
{
private string _name = String.Empty;
public CarosualImages()
{
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public string ImageName
{
get { return _name; }
set
{
_name= value;
OnPropertyChanged();
}
}
}
Put Public before
ObservableCollection<CarosualImages> list_grid { get; set; }

Resources