Я реализовал привязываемое свойство в коде содержимого. Я хочу получить доступ к этому коду для привязываемого свойства, мой код указан ниже, см.
CustomControlView.xaml
<ContentView.Content>
<StackLayout>
<Entry MyText="Text any message..." TextColor="Orange" />
</StackLayout>
</ContentView.Content>
CustomControlView.xaml.cs
public partial class CustomControlView : ContentView
{
public string MyText
{
get { return (string)GetValue(MyTextProperty); }
set { SetValue(MyTextProperty, value); }
}
// Using a DependencyProperty as the backing store for MyText. This enables animation, styling, binding, etc...
public static readonly BindableProperty MyTextProperty =
BindableProperty.CreateAttached("MyText", typeof(string), typeof(CustomControlView), "", defaultBindingMode: BindingMode.TwoWay, propertyChanged: MyTextPropertyChanged);
private static void MyTextPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var control = (Entry)bindable;
control.Text = newValue.ToString();
}
}
MainView.xaml (ContentPage)
xmlns:view="clr-namespace:MyApp.Views"
<ContextPage.Content>
<view:CustomControlView />
</ContentPage.Content>
Я хочу установить свойство MyText в Entry. Пожалуйста, дайте мне любое предложение.