If you want the value of ItemMargin
property to change when the Page.SizeChanged
event handler is triggered and then the value of ItemsMargin
in binding source changes, you need to let the SampleViewModel
implement InotifyPropertyChanged interface which notifies clients that a property value has changed, and apply the OneWay
mode in {x:Bind} extension.
For example:
public class SampleViewModel:INotifyPropertyChanged
{
private int itemM;
public int ItemsMargin
{
get { return itemM; }
set
{
if (itemM != value)
{
itemM = value;
NotifyPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public void UpdateItemsMargin(double actualWidth)
{
this.ItemsMargin = (int)actualWidth / 2;
}
}
Apply Mode=OneWay
in the binding of ItemMargin
property.
ItemMargin="{x:Bind ViewModel.ItemsMargin,Mode=OneWay}"
CLICK HERE to find out more related problems solutions.