【问题标题】:Xamarin Forms Binding two properties from a single control to different contextsXamarin Forms 将单个控件的两个属性绑定到不同的上下文
【发布时间】:2020-10-30 18:17:02
【问题描述】:

我正在编写一个 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 双精度,同时允许将 Image 的其他属性绑定到由 Binding 上下文设置的 MainPage.CabinData 类?

【问题讨论】:

    标签: xamarin data-binding


    【解决方案1】:

    在您的 XAML 中,在带有 xmlns 语句的顶部,将您的页面命名为 x:Name="MyAwesomePage"。然后你可以在 Opacity 属性中引用它:

    Opacity="{Binding CtrlTrigger, Source={x:Reference MyAwesomePage}}"
    

    【讨论】:

      猜你喜欢
      • 2018-08-08
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多