DannyRoastBeef㊙
DannyRoastBeef㊙
CC#
Created by DannyRoastBeef㊙ on 4/10/2024 in #help
(Blazor) I'm having trouble accessing a variable inside a parent component.
I'm trying to access a simple bool in a parent component that shows when my side bar has been collapsed. I'm using the Blazor Fluent UI components by the way. Okay so I've got this FluentNavMenu:
<FluentNavMenu Id="main-menu" Collapsible="true" Width="250" Title="Navigation menu" @bind-Expanded="SideBarExpanded">
...
</FluentNavMenu>

@code {

[Parameter]
public bool SideBarExpanded {get; set;}= true;
}
<FluentNavMenu Id="main-menu" Collapsible="true" Width="250" Title="Navigation menu" @bind-Expanded="SideBarExpanded">
...
</FluentNavMenu>

@code {

[Parameter]
public bool SideBarExpanded {get; set;}= true;
}
Then I've got a parent component:
<FluentStack>
...
<NavMenu (I've tried different bindings here but nothing has worked)/>
...
</FluentStack>
<FluentStack>
...
<NavMenu (I've tried different bindings here but nothing has worked)/>
...
</FluentStack>
That binding sets the SideBarExpanded every time I open or close it. I need to access it in a parent component to hide something else. What's the best way to detect that this variable has changed in the parent? There is also a component attribute I can add to the FluentNavMenu called ExpandedChanged which takes in an EventCallback, but I have no idea how to use it in the context of this particular component. I've watched this video around 10 times and I still can't wrap my head around it as this particular scenario seems different. Thanks!
4 replies
CC#
Created by DannyRoastBeef㊙ on 4/3/2024 in #help
Using ref for large data types.
Hi, just looking for a little clarification on the ref keyword when passing data into a function. I've hot an API endpoint which takes in files which passes them though to a function which checks them and sorts them into an appropriate destination directory. I've got a function in another class which checks the data type is supported, among other things. Would I be right to pass the incoming multipart File data to it using a ref value to avoid making a copy of it? Some of the files can run up to 200mb in size. Thanks for any help.
10 replies
CC#
Created by DannyRoastBeef㊙ on 7/9/2023 in #help
❔ How do I get event arguments and other data into my view model when using MVVM?
I'm using the Command interface in my XAML code on a TapGestureRecognizer ->
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:CataloguePageViewModel}},Path=TappedCommand}"
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:CataloguePageViewModel}},Path=TappedCommand}"
I'm binding it to a method in my view model which allows me to change page when I select an item from a CollectionView ->
async Task Tapped(object obj)
{
await Shell.Current.GoToAsync(nameof(Views.CatalogueDetails));
}
async Task Tapped(object obj)
{
await Shell.Current.GoToAsync(nameof(Views.CatalogueDetails));
}
I know i can use a query parameter in the URL to pass that through to the new page but how do I send my currently selected item from the CollectionView in the View xaml to my View Model so I can populate the following details page with the correct information? My current assumption is that I bind to SelectedItem in the collection view in the view xaml but I'm not sure if this is the best approach. Thanks!
8 replies
CC#
Created by DannyRoastBeef㊙ on 7/3/2023 in #help
❔ Can anyone break down this one-line code for me?
builder.Services.AddHttpClient<CatalogueService>(catalogueClient => { catalogueClient.BaseAddress = new Uri(""); });
builder.Services.AddHttpClient<CatalogueService>(catalogueClient => { catalogueClient.BaseAddress = new Uri(""); });
I'm following a tutorial surrounding using HttpClient properly. When adding as a service I noticed a syntax I don't think I've used before and I can't quite make sense of it. I think I understand that I'm setting the base address on the injected
catalogueClient
catalogueClient
but how is it doing it? What is
catalogueClient => { catalogueClient.BaseAddress = new Uri(""); }
catalogueClient => { catalogueClient.BaseAddress = new Uri(""); }
actually doing here? The parameter is
Action<HttpClient> configureClient
Action<HttpClient> configureClient
Thanks.
11 replies