【问题标题】:Set backgrund with Data-Binding from view从视图中使用数据绑定设置背景
【发布时间】:2019-07-12 13:00:20
【问题描述】:

我想使用数据绑定来设置按钮的背景图像。我可以绑定文本和 src 图像,但我缺少一些按钮...

这就是我现在所拥有的..

视图模型

public string VariantBoxGradient { get; set; } = 'imageName';

查看

_openRouteButton = FindViewById<ButtonOpacity>(Resource.Id.myId);

BindingSet.Bind(_openRouteButton).For(x => x.Background).To(vm => vm.VariantBoxGradient);

axml

<ButtonOpacity
    android:id="@+id/myId"
    ...
    // android:background="@drawable/imageName" // This i want to remove
/>

这已经行得通了

视图模型

public string VariantPic1 { get; set; } = 'step1_image';
public string TextDescriptionPic1 => string.Format('Something');

查看

var infoPic1 = FindViewById<ImageView>(Resource.Id.info_pic1);
var descriptionPic1 = FindViewById<TextView>(Resource.Id.info_description_pic1);

BindingSet.Bind(infoPic1).For("DrawableName").To(vm => vm.VariantPic1);
BindingSet.Bind(descriptionPic1).For(x => x.Text).To(vm => vm.TextDescriptionPic1);

axml

<ImageView
    android:id="@+id/info_pic1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/info_description_pic1"
    android:textSize="12sp"
    android:gravity="left" />

【问题讨论】:

    标签: c# android mvvm


    【解决方案1】:

    我解决了这个问题:

    _openRouteButton = FindViewById(Resource.Id.myId);

    _openRouteButton.SetBackgroundResource(Resources.GetIdentifier(ViewModel.VariantBoxGradient, "drawable", PackageName));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2020-01-04
      • 2018-06-05
      • 2015-07-17
      • 1970-01-01
      相关资源
      最近更新 更多