Replies: 6 comments 8 replies
-
Hey @MarkLFT thanks for the report. Yes it should "automagically" update the page :) Unfortunately I'm unable to run you application, due to the lack of But looking at your code I would suspect it's because your public void ExtendLicense(DateTime newExpiresDate)
{
ExpiresDate = newExpiresDate;
} MVUX is designed to work with immutable entities, and when you invoke A way to easily validate this theory would be to add a Then to fix it, you should convert your public partial record License(Guid Serial, Customer Customer, DateTime ExpiresDate, ImmutableList<Feature> Features, LicenseType LicenseType, LicenseOptions Options, ProductType ProductType, string AllowedVersion)
{
public string Company => Customer!.CustomerName!;
public string Name => Customer!.Name!;
public string Email => Customer!.EmailAddress!;
public string ProductTypeName => GetProductTypeName(ProductType);
public string LicenseTypeName => GetLicenseTypeName(LicenseType);
public static License NewLicense()
{
return new License
(
Guid.NewGuid(),
new Customer(),
DateTime.Today.AddYears(1),
ImmutableList<Feature>.Empty,
LicenseType.Trial,
new LicenseOptions(),
ProductType.RM,
"9.9.9000"
);
}
#region Private Helpers
private static string GetProductTypeName(ProductType productType)
{
return productType switch
{
ProductType.RM => "Resort Manager",
ProductType.RML => "Resort Manager Lite",
ProductType.Custom => "Custom",
_ => throw new NotImplementedException(),
};
}
private static string GetLicenseTypeName(LicenseType licenseType)
{
return licenseType switch
{
LicenseType.Trial => "Trial",
LicenseType.Full => "Full",
LicenseType.Error => "Error",
LicenseType.None => "None",
_ => throw new NotImplementedException(),
};
}
#endregion Private Helpers
} then the public async ValueTask ExtendLicense1Month(CancellationToken ct = default)
{
static License? extendExpiresDate(License? license)
{
if (license is null) return null;
return license with { ExpiresDate = license.ExpiresDate.AddMonths(1) };
};
await LicenseState.UpdateAsync(updater: extendExpiresDate, ct);
} |
Beta Was this translation helpful? Give feedback.
-
@dr1rrb , Many thanks for your advice, and apologies for not getting back to you sooner. I tried what you suggested, but it still did not work. I have tried several ways of returning a new License with the updated date, but still the DateTime Picker remains the same. I checked whether the converter is called a second time when the new License is returned and the LicenseState is updated, but it is not. It is only called once, when the form is initially loaded. So it appears to me to be the LicenseState.UpdateAsync does not seem to be working. Any other suggestions? Do I need to use a feed in place of an IState? |
Beta Was this translation helpful? Give feedback.
-
Hi @MarkLFT, we have been in the process of updating our sample MVUX Counter app to showcase the immutability of records. The documentation hasn't been published yet but you can find the updated code for the MVUX-C# Counter here. Consider this a straightforward approach to using records with immutability. Sample appI went ahead and made a small sample on our end to replicate your issue. This sample contains a CalendarDatePicker that displays the License's internal partial record License(DateTime ExpiresDate) {} internal partial record MainModel
{
public IState<License> License => State.Value(this, () => new License(DateTime.Now));
public ValueTask ExtendLicense1Month(CancellationToken ct)
{
static License? extendExpiresDate(License? license)
{
if (license is null) return null;
return license with { ExpiresDate = license.ExpiresDate.AddMonths(1) };
}
return License.UpdateAsync(updater: extendExpiresDate, ct);
}
} public sealed partial class MainPage : Page
{
public MainPage()
{
this.DataContext(new BindableMainModel(), (page, vm) => page
.Background(ThemeResource.Get<Brush>("ApplicationPageBackgroundThemeBrush"))
.Content(new StackPanel()
.VerticalAlignment(VerticalAlignment.Center)
.HorizontalAlignment(HorizontalAlignment.Center)
.Children(
new CalendarDatePicker()
.Date(x => x.Binding(() => vm.License.ExpiresDate)
.Converter(Converters.Converters.DateTimeOffsetConverter)
.Mode(BindingMode.TwoWay))
.Header("Expires Date"),
new Button()
.Content("Add 1 Month")
.Command(() => vm.ExtendLicense1Month)
)
)
);
}
} Data BindingAs for why the UpdateAsync is never getting called, I suspect it is because the binding to the ExtendLicense1Month task is not working. I noticed that in your views you are using: this.DataContext<BindableMainPageModel>((page, vm) => page For data binding purposes with C# markup I suggest trying this instead: this.DataContext(new BindableMainPageModel(), (page, vm) => page Let us know if this clears things up a bit! |
Beta Was this translation helpful? Give feedback.
-
@rajamatt Thanks for the feedback. After many hours of scratching my head, I finally found what my issue was. In the Binding I was using In my model, Licence is the parameter passed to the model, whereas LicenseState is the actual IState of the License. |
Beta Was this translation helpful? Give feedback.
-
I am really getting frustrated with this, it seems I keep taking one step forward, then three steps back. Based on my earlier finding that I should be binding to LicenseState, and not the passed property licence, I replace all other binding to use the LicenseState property. But now I find that upon opening the form, with the Licence passed to the model as a constructor property, that the value of IState is a new, empty, license, not the one I passed in. However, as soon as I use the AddMonth or AddYear button, the correct licence is loaded and displayed. I have tried using my original IState declaration of: I also tried to create a new instance based on the passed license: I also tried to hard code creating a new licence, and in all cases, the IState contains an empty license, until I use one of the Add buttons. What am I doing wrong in the way I create this IState? Or am I not suposed to bind to the IState properties? |
Beta Was this translation helpful? Give feedback.
-
@MarkLFT I have added another page to the previous sample that I sent to demonstrate a bit more one of the ways we can pass records through navigation between view models. Here's the updated zip file: CalendarDatePickerMVUXSample.zip. In this new sample, I made a So in the MainModel.cs we now have a internal partial record MainModel(License License)
{
public IState<License> LicenseState => State.Value(this, () => License);
public ValueTask ExtendLicense1Month(CancellationToken ct)
{
static License? extendExpiresDate(License? license)
{
if (license is null) return null;
return license with { ExpiresDate = license.ExpiresDate.AddMonths(1) };
}
return LicenseState.UpdateAsync(updater: extendExpiresDate, ct);
}
} Because we want to pass a private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap(ViewModel: typeof(ShellModel)),
new ViewMap<WelcomePage, WelcomeModel>(),
new ViewMap<MainPage, MainModel>(Data: new DataMap<License>())
);
routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellModel>(),
Nested:
[
new ("Welcome", View: views.FindByViewModel<WelcomeModel>()),
new ("Main", View: views.FindByViewModel<MainModel>()),
]
)
);
} Finally, when we want to navigate to the MainModel page, we can bind the public async ValueTask NavigateToMainPage()
{
await _navigator.NavigateViewModelAsync<MainModel>(this, data: await SelectedLicense);
} |
Beta Was this translation helpful? Give feedback.
-
I am having trouble getting a date picker on a page to update when I change the value in code. I am using mvux, and the data object we bind to is an IState of a class.
The view model looks like this:
On the page is a button with the command property set to vm.ExtendLicense1Month, and I can see the correct method is being called, and the license instance is having the date updated. All seems normal, except the date picker is not updated to the new value.
Below is the binding:
Is there another command I need to issue to trigger an update of the page? I thought mvux is Reactive based, so should notice the changes and update the page automagically.
The full code can be seen at https://github.com/MarkLFT/RMUtility.Problems
Beta Was this translation helpful? Give feedback.
All reactions