Я пытаюсь добавить ползунок и холст на главную страницу. Значение ползунка будет контролировать высоту нарисованной фигуры. Однако мне очень трудно связать свойства.
Я не уверен, как выполнить привязку к классу ресурсов.
Мой вид
<ContentPage.BindingContext>
<viewmodel:MainViewModel />
</ContentPage.BindingContext>
<ContentPage.Resources>
<charts:CustomChart x:Key = "drawable"></charts:CustomChart>
</ContentPage.Resources>
<ScrollView>
<VerticalStackLayout>
<HorizontalStackLayout
Spacing = "25"
Padding = "30,0"
VerticalOptions = "Center">
<Slider
x:Name = "Sldr"
Minimum = "0.3"
Maximum = "1.0"
Value = "{Binding Hayt}"
WidthRequest = "200"
/>
</HorizontalStackLayout>
<GraphicsView>
<GraphicsView.Drawable>
<charts:CustomChart Grid_Height = "{Binding Hayt}" />
</GraphicsView.Drawable>
</GraphicsView>
</VerticalStackLayout>
</ScrollView>
Моя модель представления
internal class MainViewModel : BaseViewModel
{
double hayt;
public double Hayt
{
get { return hayt; }
set
{
if (hayt != value)
hayt = value;
OnPropertyChanged();
}
}
}
Мой класс Grapview
internal class CustomChart : GraphicsView, IDrawable
{
// Screen Parameters
readonly float ScreenWidth = (float)DeviceDisplay.MainDisplayInfo.Width;
readonly float ScreenHeight = (float)DeviceDisplay.MainDisplayInfo.Height;
readonly float Density = (float)DeviceDisplay.MainDisplayInfo.Density;
public double Grid_Height
{
get => (double)GetValue(Grid_Height_Adjuster);
set => SetValue(Grid_Height_Adjuster, value);
}
public static readonly BindableProperty Grid_Height_Adjuster = BindableProperty.Create(nameof(Grid_Height),typeof(double),typeof(CustomChart),0.7);
public void Draw(ICanvas canvas, RectF dirtyRect)
{
float Y_Top = dirtyRect.Top;
float Y_Bot = dirtyRect.Bottom / Density * (float)Grid_Height;
float X_Right = dirtyRect.Right / Density;
float X_Left = dirtyRect.Left;
}
}
Когда я пытаюсь, Как передать переменные данные в холст .net MAUI GraphicsView, .Net говорит => Не найдено свойство, BindableProperty или событие для "Grid_Height" или несоответствие типа между значением и свойством.





Предыдущий код:
public double Grid_Height
{
get => (double)GetValue(Grid_Height_Adjuster);
set => SetValue(Grid_Height_Adjuster, value);
}
public static readonly BindableProperty Grid_Height_Adjuster = BindableProperty.Create
(nameof(Grid_Height),typeof(double),typeof(CustomChart),0.7);
Измените на это:
public double Grid_Height
{
get => (double)GetValue(Grid_HeightProperty);
set => SetValue(Grid_HeightProperty, value);
}
public static readonly BindableProperty Grid_HeightProperty = BindableProperty.Create
(nameof(Grid_Height),typeof(double),typeof(CustomChart),0.7);
При создании привязываемого свойства необходимо сохранить формат именования
"Название свойства+Property". Для получения более подробной информации вы можете проверить этот документ.
Из документов: Соглашение об именах для привязываемых свойств заключается в том, что идентификатор привязываемого свойства должен соответствовать имени свойства, указанному в методе Create, с добавленным к нему «Свойством».