Ho un oggetto di disegno SkiaView. Creo molti SkiaView nel file xaml, quindi sto cercando un modo per passare proprietà personalizzate al mio SkiaView.
Ho provato questo:
(Autore: https://codemilltech.com/back-to-school-adding-a-custom-bindable-property-to-xamarin-forms/)
public static readonly BindableProperty TestVarProperty =
BindableProperty.Create<SkiaView, string>(rv => rv.TestVar,"None",
BindingMode.TwoWay, (bindable,value)=> { return true; },
(bindable, oldValue, newValue) => {
var thisView = (SkiaView)bindable;},
(bindable, oldValue, newValue) => {},
(bindable, value) => {
return value;
}, (bindable) => {
return ">Error<";
});
public string TestVar
{
get { return (string)GetValue(TestVarProperty); }
set { SetValue(TestVarProperty, value); }
}
Ma questo restituisce la stringa "none", vorrei ottenere e usare il mio set TestVar in xaml. Quindi, se qualcuno ha un'idea per passare la proprietà a un oggetto senza Bindable Property, lo prendo.
risposte:
1 per risposta № 1Grazie per la tua risposta, ho cambiato il codice qui sotto in questo modo
public static readonly BindableProperty TestVarProperty =
BindableProperty.Create<SkiaView, string>(rv => rv.TestVar, null,
BindingMode.OneWayToSource);
public string TestVar
{
get { return (string)GetValue(TestVarProperty); }
set { SetValue(TestVarProperty, value); }
}
E funziona!