C
C#3mo ago
Mekasu0124

✅ Allow user to select profile image avalonia

https://docs.avaloniaui.net/docs/concepts/services/storage-provider/file-picker-options I found this on the docs, but I think I'm looking in the wrong place. On the create new user screen in my application, I want to have a part where the user can select a file from their local computer to set as their profile image, however, I'm not having much luck finding any examples, or other users on like Stack Overflow who are trying to do the same thing. Thanks in advance.
10 Replies
Klarth
Klarth3mo ago
That's definitely how you do it. Or at least part of it. You should use OpenFilePickerAsync from the above page: https://docs.avaloniaui.net/docs/concepts/services/storage-provider/
StorageProvider | Avalonia Docs
The StorageProvider is central to file and folder management. It provides methods for file and folder selection, checking platform capabilities, and interacting with stored bookmarks.
Mekasu0124
Mekasu01243mo ago
ok from what I can see, it's just the ViewModel code? So I'm assuming I would need to bind that function a button for the functionality that I'm wanting?
Klarth
Klarth3mo ago
That's not related to VM at all. You can call it from the VM, but it's meant to be called from the View. You can write a service class for the functionality and call it from your VM though.
Mekasu0124
Mekasu01243mo ago
oh if it's meant to come from the view, then I would rather do that. I've just never done anything in the view's code behind. Never thought I was supposed to well since I'm using the code behind to obtain a user selected profile image, another question for you is if I have a text box
<TextBox Classes="NewUserInput" Grid.Row="3" Grid.Column="1" Text="{Binding UserBirthday}" />
<TextBox Classes="NewUserInput" Grid.Row="3" Grid.Column="1" Text="{Binding UserBirthday}" />
and I want to format and validate the user's input while they're typing in their birthday. For example: - user enters 1, program determines if integer, yes display 1 else don't show anything. - user enters 2, program determines if integer, yes then check if valid month => 12 = december, yes, then show 12/ - user enters G, program determines if integer, no not integer, do not show input. - user enters 3, program determines if integer, yes display 12/3 else don't show anything and so on for the user's birthday as they're entering it in. How would I do that in the view's code behind? I found the TextInput event for the TextBox control, but I can't figure out how to activate it
Klarth
Klarth3mo ago
You should be using a time control instead, like DatePicker.
Mekasu0124
Mekasu01243mo ago
I can't figure out how to style the date picker for when it's closed and open. I have the API pulled up in another editor, but can't figure out how to read the Avalonia\AvaloniaFramework\src\Avalonia.Themes.Fluent\Controls\DatePicker.xaml styles page otherwise, I would be using that
Klarth
Klarth3mo ago
It's not exactly trivial to use TextInput to filter in-progress date entry in a way that isn't janky. It's a complex control and not well-written, TBH. Still a better bet than reimplementing part of it, IMO.
Mekasu0124
Mekasu01243mo ago
so lik ethe applications theme is Black (background), Royal Blue(border), and Dark Gray(foreground). I want the stylings of the datepicker whether it's open, close, on hover start, or on hover end, on click, on date selected, everything; it all needs to look the same and I can't figure out the DatePicker's stylings 😂
Klarth
Klarth3mo ago
There should be like a billion selectors. I would probably copy/paste and work from a fresh template though. Some components will inevitably not be customizable. It should activate on any text input. You need to subscribe to it like any event though.
Mekasu0124
Mekasu01243mo ago
ok but I feel like the DatePicker is more appropriate and safe. so I'll just need to figure out the stylings