frostfina
❔ Generic method that takes in a struct and calls the correctly-typed method
I'm working with OpenTK (an OpenGL binding) and I'd like to create a method that allows setting uniforms (basically variables inside of a shader).
The solution I've come up with is the following. For context,
Matrix4
is a struct
. This method is part of my Shader
class, in which I'm trying to abstract the native types.
The cast (Matrix4)value
doesn't work though. I wrote it like this so that I can write a single method to set any type of uniform value, here the only implemented one is Matrix4
.
My question is : Is there a way to make this work, or do I have to write a method for each type of argument?
If that's a bad solution, what would be a good one?
(Alternatively, I could abstract uniforms further with an Uniform
class so I'm not directly working with the native types in my shader abstraction, but that would also require adding an abstraction for the uniform use cases.)20 replies
Passing a string property to a command via a button CommandParameter in .NET 6
Hello
So I'm trying to pass a string (that's bound to a text field via a data context
<TextBox [...] Text="{Binding SearchString}"/>
which I made sure already works) using a button's CommandParameter
. The relevant button code is as follows (I've hidden layout arguments)
PerformSearch
is a property of the class MainViewModel
that I have defined as a custom class
This does however not work, pressing the button does call the command and I do see
in the program's output, however after testing parameter
is null. If I pass a string directly instead of using a binding, I do get the string as an output
which produces
What am I doing wrong with my previous binding? Maybe this is the wrong way of handling button presses? I've seen people just use CommandParameter="Binding"
and pass the whole ViewModel, and it does indeed pass the whole viewmodel, but I feel like it defeats the purpose of having a separate class handle the command.28 replies