43 Replies
The source property expects type
IImage
You could try the approach they say in the avalonia docs named Binding to Image Files from Various Sources
(It's basically setting the IImage to something like a bitmap in the documentation case with
Additionally you can try out other types that are also of type IImage like these:Xaml doesn't necessarily confirm to C# standards, providing a path isn't always converted as a string
I tried that. I even tried to use their ImageHelper class and it didn't work for me. I wound up trying
and that worked beautifully
Great! Just note that you can shave off the tail bit of that if not needed
like
I tried doing a self-closing tag, and it wouldn't work unfortunately
but then again, half of this framework doesn't work for me
You still want to use binding for it right?
I'm using Visual Studio. When I type in the axaml file, there is no drop down box for code completion and I cannot use the Designer either. idk why it's all broken. I have tried every solution I could find to fix it. I've asked in the Microsoft discord, and here, but got no responses. It's just broken, and I want to stay up to date with the framework. I'm currently using 11.0.2 or whatever it is, and therefore I'm not wanting to back date just to get those features back
no. I'm not changing images throughout the process. It's the same image each time so I just typed it straight in
Whats the problem with just keeping it like
compared to making it a binding?
I'm not making it a binding? There is no problem?
I'm confused on the question
There is no problem on having the path in the Image tag like that. That's what I did
Oh, so the problem aint that you want it to display as a binding but instead you want to make it display? like its not appearing despite both attempts.
Um, lemme get visual studio out since idk how it looks like in visual studio, it may be a resource property issue
In Rider its usual that you mark it as an "AvaloniaResource" like in this screenshot
Is your icon set to it like this?
no the problem was that it wasn't displaying at all, but then I tried this and it worked.
the image displays just fine now. The problem I'm on right now is getting a screen to display a style for when an input is wrong, and then getting the screen to refresh after n seconds and put the stylings back to normal
You could use classes. You can add or remove classes and on the axaml side change how they look based upon each class
Then from the code-behind side, you set the classes and remove them as you wish.
Classes is a collection, like a list, so adding something would be
View => https://pastebin.com/2mC6kC9X
ViewModel => https://pastebin.com/D0bBd00K
What I'm trying to accomplish is that in this function
when it hits the early return because the username they're trying to create already exists, it will show the error styling which is based off the
IsValid
bool. After 3 seconds, it will reset the screen. I tried doing
but that didn't allow the error styling to show and just froze and reset the screen
the way it's supposed to work is if I go to create a new username in the text box, and that username already exists in the current users list, then it will change the styling of the text box and swap the button with a label in the view. Once that change happens, I want the program to count down 3 seconds, and then reset the screen. This, I believe, has to be controlled from the main window view model since that's what handles the returned model which is returned from the button click on that view
so if I select a username from the combo box, and click login, it will send that username back to main window view model. If I enter a new username that doens't exist in the combo box and click the play game button, then it'll save it to the database, and return that new username back to the main window view model. If I enter in a username in the text box that already exists in the combo box and click the play game button, it'll early escape and send a null model back to the main window view model and if that model is null else { SelectUser(); }
then I want the error styling to still show on the screen, the system to sleep for 3 seconds, and then refresh the screenas it sits right this second, if I put in my username which already exists. It just simply resets the screen. No error stylings show, the label doesn't show and the button hide. It just resets the screen
just froze and reset the screenthats exactly what this part is doing. Since its not async code and is executing on the main thread Thread.Sleep freezes your entire application What prevents you from returning a Tuple like ? Also I can't see any code that actually does styling on the ReturnNewUser method failing by returning an "IsValid = false" object but what you can do is, when that method returns, check the value, add a class to the Control that shows an error state and then maybe after 3 sec remove that, or set the control / window properties directly like: You could also set it as a class or even create a ViewModelBinding for their respective IsVisible states like this
Dialogs are also an option
just frose and reset the screen Thread.Sleep(3000); Select User();
thats exactly what this part is doing, Since it's not async code and is executing on the main thread Thread.Sleep freezes your entire application
that's what I thought too, but I can't figure out any other way.
What prevents you from returning a Tuple like public (bool Success, User NewUser) ReturnNewUser();
?
I didn't know that was an option. I'm still a beginner at most things C# and Avalonia related.
Also I can't see any code that actually does styling on the ReturnNewUser method failing by returning an "IsValid = false" object but what you can od is, when that method returns, check the value, add a class to the Control that shows an error state and then maybe after 3 sec remove that, or set the control / window properties directly like User x = ReturnNewUser(); if (!x.IsValid) { window.MyFancyLabel.IsVisible = true; window.MyFancyButton.IsVisiable = false; }There are stylings. It's in a separate style file. The styles are done off conditional rendering like this Which is based off the IsValid boolean within the ViewModels code.
You could also set it as a class or even create a ViewModelBinding for their respective IsVIsible states like this <screenshot> Dialogs are also an optionI don't know anything about dialogs, tbh. I want the main window view model to control the stylings being applied through the IsValid bool like I have it setup, but if that's not efficient, then I'll re-write it to whatever is most efficient and the best practice. I just don't know what that is. I'm still learning the best methods of doing things with this framework
ah gotcha, i see, um for the "async code" part. You could change your subscribe method to dispatch an async event to the UI after 3sec
1sec i show dispatcher code
if I do this, then the stylings get applied. I just don't know the best way to have the program sleep and then reset the screen
so I would set the IsValid to false before the dispatcher, right?
Yes
The dispatcher just makes sure your application doesnt freeze when doing async operations
just please dont use any Thread.Sleeps in UI code
I do my best not to. Most times they're just placeholders until I can find a better way to do what I'm wanting to do. Like in this instance for example
and that you for showing me the dispatcher. That works amazingly. Thank you!
also for synchronous code you can do
for if you're on another thread and want to send something to the main thread.
oh ok. cool. tyvm
what's a more efficient way to create a string list of numbers 1 through 25 inclusive with having "Select One" at index 0 than this?
arion
REPL Result: Success
Result: List<string>
Compile: 618.281ms | Execution: 69.272ms | React with ❌ to remove this embed.
like that?
You could even do
arion
REPL Result: Success
Result: List<string>
Compile: 638.474ms | Execution: 71.405ms | React with ❌ to remove this embed.
very much appreciated 🙂
npnp
lets say I have a list of text
instead of creating a for-loop to bring all of that text together
how would I apply that enumerable thing you did with the numbers above to bring the list together instead? I know I can do
but I don't like how that presents in a textblock
would I use
string.Join(" ", text);
?I don't exactly know what you want. Do you want something like this?
seems Modix cant do newlines properly with raw literals, um i'll just post raw
Splitting by \r\n is a windows thing called CRLF
There are 3 options, windows is CRLF, basically, splitting by \n is for linux, \r\n is for windows (in this context)
arion
REPL Result: Success
Result: string[]
Compile: 515.625ms | Execution: 33.204ms | React with ❌ to remove this embed.
So in your case, just add change the
from the modix repl to
ok thank you ❤️