binding property shadows net maui android

ivanik62

New member
Joined
Aug 30, 2024
Messages
2
Programming Experience
Beginner
good morning everyone, sorry but I'm a very very newbie and I don't even know how to ask the right questions.

I wanted to ask if there is a possibility to create a binding for the shadow properties of a control (eg. a button)

Something that could look like this.

Class:
C#:
public class Shadows
 {
     public string Brush { get; set; } = "Black";
     public string Offset { get; set; } = "50,50";
     public string Radius { get; set; } = "10";
     public string Opacity { get; set; } = "0.7";
 }

XAML:
C#:
<Button
        x:Name="CounterBtn"
        Text="Click me"
        SemanticProperties.Hint="Counts the number of times you click"
        Clicked="OnCounterClicked"
        BorderColor="DarkBlue"
        BorderWidth="1"
        HorizontalOptions="Fill" >
    <Button.Shadow>
       <Shadow
               Brush="{Binding ControlShadow.Brush}"
               Offset="{Binding ControlShadow.Offset}"
               Radius="{Binding ControlShadow.Radius}"
               Opacity="{Binding ControlShadow.Opacity}" />
    </Button.Shadow>
 </Button>

MainPage:
C#:
public partial class MainPage : ContentPage
{
    int count = 0;
    public Shadows ControlShadow { get; set; }
    public MainPage()
    {
        InitializeComponent();
        ControlShadow = new Shadows();
        BindingContext = this;
    }
}

As posted it doesn't work
Thanks to everyone.
 
Solution
The documentation suggests that binding is supported:

I'm wondering if you are using the right type for the various properties that you are trying to bind, though. Your Shadows class defines everything to be strings, but the documentation says they should be various other types:
  • Radius, of type float, defines the radius of the blur used to generate the shadow. The default value of this property is 10.
  • Opacity, of type float, indicates the opacity of the shadow. The default value of this property is 1.
  • Brush, of type Brush, represents the brush used to colorize the...
The documentation suggests that binding is supported:

I'm wondering if you are using the right type for the various properties that you are trying to bind, though. Your Shadows class defines everything to be strings, but the documentation says they should be various other types:
  • Radius, of type float, defines the radius of the blur used to generate the shadow. The default value of this property is 10.
  • Opacity, of type float, indicates the opacity of the shadow. The default value of this property is 1.
  • Brush, of type Brush, represents the brush used to colorize the shadow.
  • OffSet, of type Point, specifies the offset for the shadow, which represents the position of the light source that creates the shadow.
 
Solution
Ta
La documentazione suggerisce che il binding è supportato:
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/shadow?view=net-maui-8.0

Mi chiedo se stai usando il tipo giusto per le varie proprietà che stai cercando di associare, però. La tua Shadowsclasse definisce tutto come strings, ma la documentazione dice che dovrebbero essere vari altri tipi:

Grazie tantissimo. Sono veramente un novizio e questo mi era sfuggito. Mi hai risolto il problema. Grazie ancora.
 
Back
Top Bottom