首页 > 解决方案 > 向 VM 发送字节不起作用 Xamarin

问题描述

我有行为

    public class FolderDialogBehavior : Behavior<View>
    {
        public byte[] ImageBytes{ get { return (byte[])GetValue(ImageBytesProperty); } set { SetValue(ImageBytesProperty, value); } }

        public readonly static BindableProperty ImageBytesProperty = BindableProperty.Create(nameof(ImageBytes), typeof(byte[]),
            typeof(FolderDialogBehavior), defaultValue: null, BindingMode.TwoWay);


        //  Some Code


        private async void GetPhotoAsync()
        {
            // Some Code


            ImageBytes = bytes;
        }
    }

我也有 ViewModel

    public class StudentViewModel : OnPropertyChangedClass
    {
        private byte[] _userImage;

        public byte[] UserImage  
        { 
            get => _userImage;  
            set => SetProperty(ref _userImage, value); 
        }
    }

问题是 ImageBytes 不会向我的 ViewModel 发送新信息。如果我将byte[]更改为字符串,一切正常

<Grid Content BindingContext="{Binding AddEmployee, Mode=OneWay}">
    <Grid.Behaviors>
        <local:FolderDialogBehavior ImageBytes="{Binding StudentObject.UserImage, Mode=TwoWay}"/>
    </Grid.Behaviors>
</Grid>

标签: xamarinpropertiesbytebehavior

解决方案


推荐阅读