我正在编写Xamarin Forms应用程序,并将XAML控件的各种属性绑定到所有页面共享的通用类结构上。为了通知我的代码,当前在首页上显示哪些控件,我触发了一个事件,并在处理程序中确定了该控件是否可见。我想使用不是类结构一部分的局部变量来触发事件。
<mr:Image ClassId="3" Source="{Binding ImagesDictionary[AudioOnOff],Converter={StaticResource imageFileToImageSourceConverter}}"
PropertyChanged="Image_PropertyChanged"
Opacity="{Binding CtrlTrigger}"
Down="Control_Image_Tapped"
InputTransparent="{Binding InhibitTouch}" />
C#
public partial class HomePage : ContentPage, INotifyPropertyChanged
{
public double CtrlTrigger; // I'll connect this to a notify event, understood.
protected override void OnAppearing()
{
BindingContext = MainPage.CabinData;
}
}
如何将Opacity属性仅绑定到HomePage中的CtrlTrigger double,同时允许将Image的其他属性绑定到Binding上下文设置的MainPage.CabinData类?
在XAML中,在xmlns语句的顶部,为您的页面命名,例如x:Name="MyAwesomePage"
。然后,您可以在Opacity属性中引用它:
Opacity="{Binding CtrlTrigger, Source={x:Reference MyAwesomePage}}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句