Navigation data on 3rd party items control #2362
-
<sfTreeGrid:SfTreeGrid ItemsSource="{x:Bind ViewModel.BuildingsAndComplexes, Mode=OneWay}"
uen:Navigation.Request="Building"
AllowDraggingColumns="True"
AllowResizingColumns="True"
AllowSorting="True"
AutoGenerateColumns="False"
ChildPropertyName="Buildings"> When I navigate from an item to a page data is null, why? As I see in docs https://platform.uno/docs/articles/external/uno.extensions/doc/Learn/Navigation/HowTo-NavigateInXAML.html#3-navigating-to-selecteditem data must be filled. |
Beta Was this translation helpful? Give feedback.
Answered by
xperiandri
Jun 22, 2024
Replies: 1 comment
-
Specific MUST BE ADDED TO DI HERE .UseNavigation(ReactiveViewModelMappings.ViewModelMappings, RegisterRoutes, configureServices: (context, services) => services
.AddSingleton<IRequestHandler, SfDataGridRequestHandler>()
.AddSingleton<IRequestHandler, SfTreeGridRequestHandler>()
) using Syncfusion.UI.Xaml.DataGrid;
/// <summary>
/// Navigation request handler for <see cref="SfDataGrid"/> controls.
/// </summary>
/// <param name="HandlerLogger">Logger for logging</param>
public record SfDataGridRequestHandler(ILogger<SfDataGridRequestHandler> HandlerLogger) : ControlRequestHandlerBase<SfDataGrid>(HandlerLogger)
{
/// <inheritdoc/>
public override IRequestBinding? Bind(FrameworkElement view)
{
var viewToBind = view;
var dataGrid = view as SfDataGrid;
if (dataGrid is null)
{
if (Logger.IsEnabled(LogLevel.Warning))
{
Logger.LogWarningMessage($"Bind: {view?.GetType()} is not a SfDataGrid");
}
return default;
}
async Task Action(FrameworkElement sender, object data)
{
var navdata = sender.GetData() ?? data;
var path = sender.GetRequest();
var nav = sender.Navigator();
if (nav is null || navdata is null)
{
return;
}
await nav.NavigateRouteAsync(sender, path, Qualifiers.None, navdata);
}
async void TapAction(object? actionSender, GridCellDoubleTappedEventArgs actionArgs)
{
var sender = actionSender as SfDataGrid;
if (!(sender?.IsDoubleTapEnabled ?? false))
{
return;
}
var data = sender.GetData() ?? actionArgs.Record;
await Action(sender, data);
}
Action? connect = () => dataGrid.CellDoubleTapped += TapAction;
Action? disconnect = () => dataGrid.CellDoubleTapped -= TapAction;
if (dataGrid.IsLoaded)
{
connect();
}
void LoadedHandler(object s, RoutedEventArgs e) => connect();
dataGrid.Loaded += LoadedHandler;
void UnloadedHandler(object s, RoutedEventArgs e) => disconnect();
dataGrid.Unloaded += UnloadedHandler;
return new RequestBinding(viewToBind, LoadedHandler, UnloadedHandler);
}
} using Syncfusion.UI.Xaml.TreeGrid;
/// <summary>
/// Navigation request handler for <see cref="SfTreeGrid"/> controls.
/// </summary>
/// <param name="HandlerLogger">Logger for logging</param>
public record SfTreeGridRequestHandler(ILogger<SfTreeGridRequestHandler> HandlerLogger) : ControlRequestHandlerBase<SfTreeGrid>(HandlerLogger)
{
/// <inheritdoc/>
public override IRequestBinding? Bind(FrameworkElement view)
{
var viewToBind = view;
var treeGrid = view as SfTreeGrid;
if (treeGrid is null)
{
if (Logger.IsEnabled(LogLevel.Warning))
{
Logger.LogWarningMessage($"Bind: {view?.GetType()} is not a Selector");
}
return default;
}
async Task Action(FrameworkElement sender, object data)
{
var navdata = sender.GetData() ?? data;
var path = sender.GetRequest();
var nav = sender.Navigator();
if (nav is null || navdata is null)
{
return;
}
await nav.NavigateRouteAsync(sender, path, Qualifiers.None, navdata);
}
async void TapAction(object? actionSender, TreeGridCellDoubleTappedEventArgs actionArgs)
{
var sender = actionSender as SfTreeGrid;
if (!(sender?.IsDoubleTapEnabled ?? false))
{
return;
}
var data = sender.GetData() ?? actionArgs.Record;
await Action(sender, data);
}
Action? connect = () => treeGrid.CellDoubleTapped += TapAction;
Action? disconnect = () => treeGrid.CellDoubleTapped -= TapAction;
if (treeGrid.IsLoaded)
{
connect();
}
void LoadedHandler(object s, RoutedEventArgs e) => connect();
treeGrid.Loaded += LoadedHandler;
void UnloadedHandler(object s, RoutedEventArgs e) => disconnect();
treeGrid.Unloaded += UnloadedHandler;
return new RequestBinding(viewToBind, LoadedHandler, UnloadedHandler);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
xperiandri
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Specific
IRequestHandler
is requiredMUST BE ADDED TO DI HERE