C
C#2y ago
Jona4Play

✅ Help with Avalonia Templated Controls

I am currently working on a templated control for a sliding button. I, however, get an error for the binding of the Click Event to the Method SwitchStates saying that it is unable to find a suitable getter or setter. Do you have to bind differently? I cant use Command, as this is something I want to make accessible from the outside.
6 Replies
Jona4Play
Jona4PlayOP2y ago
Here the Button XAML
<Button
x:Name="SlidingButton"
Background="Transparent"
Click="SwitchStates"
Command="{TemplateBinding Command}"
CornerRadius="25">
<Button
x:Name="SlidingButton"
Background="Transparent"
Click="SwitchStates"
Command="{TemplateBinding Command}"
CornerRadius="25">
This is the relevant Code behind of the Templated Control.
public class ActiveMenuItems : TemplatedControl
{
public void SwitchStates(object sender, RoutedEventArgs e)
{
IsOn ^= true;
}
...
public class ActiveMenuItems : TemplatedControl
{
public void SwitchStates(object sender, RoutedEventArgs e)
{
IsOn ^= true;
}
...
The other Styled Properties are tied to the IsOn property.
Klarth
Klarth2y ago
There's already a control for this. It's called ToggleSwitch. Not sure if it was on 0.10.x or if it's 11-preview.
Klarth
Klarth2y ago
Klarth
Klarth2y ago
<ToggleSwitch Content="Testing" />
HimmDawg
HimmDawg2y ago
It exists in 0.10.21
Jona4Play
Jona4PlayOP2y ago
Oh right. Didn't know that. Thanks!
Want results from more Discord servers?
Add your server