I have a grid element with the x:Load attribute bound to a variable in the page:
Page.xaml
<Page>
...
<Grid x:Name="grd" x:Load="{x:Bind LoadGrid, Mode=OneWay}">
Page.xaml.cs
public sealed partial class Page : Page
...
bool LoadGrid;
After receiving the passed argument from the OnNavigatedTo event handler, I set the value of LoadGrid accordingly:
request = (Request) e.Parameter;
if (request == null)
LoadGrid = false;
else {
LoadGrid = true;
InitializeComponent(); // Tried adding this to refresh the controls.
grd.Loaded += grd_Loaded;
}
When the line grd.Loaded += grd_Loaded; is executed, an ArgumentException is thrown:
An exception of type 'System.ArgumentException' occurred ...
Delegate to an instance method cannot have null 'this'.
I check and the value of grd is null even though the x:Load property is true and the binding mode is OneWay (the control "checks" for updates in the bound value).
Edits
ATTEMPT 1
Calling this.InitializeComponent() to re-init the controls.
ATTEMPT 2 suggested by @touseefbsb:
Use the MVVM approach to create an event for updating the property value.
ATTEMPT 3
Tried .FindName("grd") after setting the load value, didn't work.
{x:Bind}defaults toOneTime, while{Binding}which is used with WPF defaults toOneWay. docs.microsoft.com/en-us/windows/uwp/xaml-platform/… - fourwhey