Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem doing a data binding in GraphicView #16671

Closed
vsfeedback opened this issue Aug 10, 2023 · 3 comments
Closed

Problem doing a data binding in GraphicView #16671

vsfeedback opened this issue Aug 10, 2023 · 3 comments
Labels
area/drawing ✏️ Shapes, Borders, Shadows, Graphics, custom drawing s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity t/bug Something isn't working

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


I need to do a data binding, using BindableProperty in a GraphicView using MVVM but it does not work. I'm working NET MAUI also I'm using the Nuget CommunityToolkit.Mvvm.
My drawable class is :

 public class DibujarArcoGreenwich : GraphicsView, IDrawable
 {
        public float AnguloFin
        {
            get => (float)GetValue(AnguloFinProperty);
            set => SetValue(AnguloFinProperty, value);
        }
        public static readonly BindableProperty AnguloFinProperty =
            BindableProperty.Create(nameof(AnguloFin), typeof(float), typeof(DibujarArcoGreenwich));
            
            public void Draw(ICanvas canvas, RectF dirtyRect)
        {
            //dibujo arco
            float finalgrados = 360 - AnguloFin;
            canvas.StrokeColor = Color.Red;
            canvas.StrokeSize = 6;
            int xposicion = XPosicionCentro - Radio;
            int yposicion = YPosicionCentro - Radio;
            canvas.DrawArc(10, 10,90,90, 0, finalgrados, true, false);
           }

}

My viewmodel is :

public partial class AriesViewModel : ObservableObject, INotifyPropertyChanged
   {
       [ObservableProperty]
       float _anguloFin;
        public AriesViewModel()
       {
           AnguloFin = 0;
       }
       [RelayCommand]
       private void CalcularAries()
       {
           AnguloFin = HacerCalculos(); // always return a value
       }
    }

My page XAML is :
    <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace:NautorStar.MisControles"
            xmlns:viewModels="clr-namespace:NautorStar.ViewModels"
            xmlns:drawables="clr-namespace:NautorStar.ClasesDibujo"
            x:Class="NautorStar.AriesPage"
            Title="Aries">
   <ContentPage.BindingContext>
       <viewModels:AriesViewModel />
   </ContentPage.BindingContext>
    <StackLayout>
                 <GraphicsView 
                           HorizontalOptions="Center"
                           VerticalOptions="Center"
                           HeightRequest="250"
                           WidthRequest="400">
                <GraphicsView.Drawable>
                    <drawables:DibujarArcoGreenwich           
                           AnguloFin="{Binding AnguloFin, Mode=TwoWay}"/>
                  </GraphicsView.Drawable>
            </GraphicsView>
             <Button Text="Calcular"
                   Command="{Binding CalcularAriesCommand}" />
       </StackLayout>
</ContentPage>

But always AnguFin in my class DibujarArcoGreenwich is 0, the binding does not work.
if I change the xaml


                    <drawables:DibujarArcoGreenwich           
                           AnguloFin="{Binding AnguloFin, Mode=TwoWay}"/>
                  </GraphicsView.Drawable>
                  

for :


                      <drawables:DibujarArcoGreenwich           
                           AnguloFin="156"/>
                  </GraphicsView.Drawable>

the arc is drawn correctly. It is as if the Binding did not work correctly
How can I solve this problem ?? Have I forgotten to do something?
Thanks


Original Comments

Feedback Bot on 8/9/2023, 08:20 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@samhouts samhouts added the t/bug Something isn't working label Aug 10, 2023
@Eilon Eilon added the area/drawing ✏️ Shapes, Borders, Shadows, Graphics, custom drawing label Aug 10, 2023
@mattleibow
Copy link
Member

To update you also need to call GraphicsView.Invalidate(). Updating a property on the object does not automatically trigger a refresh.

Let me know if this works.

@mattleibow mattleibow added the s/needs-info Issue needs more info from the author label Aug 11, 2023
@ghost
Copy link

ghost commented Aug 11, 2023

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Aug 15, 2023
@ghost
Copy link

ghost commented Aug 15, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@ghost ghost closed this as completed Aug 18, 2023
@dotnet dotnet locked as resolved and limited conversation to collaborators Sep 17, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/drawing ✏️ Shapes, Borders, Shadows, Graphics, custom drawing s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants