[英]Binding to Object Property in ViewModel issue
Not sure why this isn't working... Below I is my ViewModel which is set to my View DataContext. 不知道为什么这不起作用...下面是设置为View DataContext的ViewModel。
public class UploadViewModel : CrudVMBase
{
#region Commands
public CommandVM UploadButtonCommand { get; set; } =
new CommandVM
{
CommandDisplay = "Perform Upload",
IconGeometry = App.Current.Resources["pencil30"] as Geometry,
Message = new CommandMessage { Command = CommandType.UploadFromCamera }
};
#endregion End Commands
#region Public Properties
UploadInitiation UploadObject { get; set; } = new UploadInitiation();
#endregion End Public Properties
public UploadViewModel()
{
}
Below is the UploadInitiation class 下面是UploadInitiation类
public class UploadInitiation : Common.NotifyUIBase
{
#region Public Properties
public ObservableCollection<UploadStep> Steps { get; set; } = new ObservableCollection<UploadStep>();
public int UploadProgress { get; set; } = 45;
public string UploadTask { get; set; } = "Idle...";
public bool UploadEnabled { get; set; } = false;
public bool UploadBegin { get; set; } = false;
#endregion END Public Properties
public UploadInitiation()
{
// Populate steps required, ensure upload returns UI updates
Steps.Add(new UploadStep { Message = "Seperate upload to new thread...", Complete = false, Error = null });
Steps.Add(new UploadStep { Message = "Generate new file names...", Complete = false, Error = null });
Steps.Add(new UploadStep { Message = "Render Thumbnails, add to database...", Complete = false, Error = null });
Steps.Add(new UploadStep { Message = "Move images ready for print...", Complete = false, Error = null });
}
}
This is my Binding, as you can see im trying to Bind to the UploadProgress
Property. 这是我的绑定,如您所见,我正在尝试绑定到
UploadProgress
属性。
<ProgressBar Style="{StaticResource CircularProgress}" Width="180" Value="{Binding UploadObject.UploadProgress}" />
Here is the error 这是错误
System.Windows.Data Error: 40 : BindingExpression path error: 'UploadObject' property not found on 'object' ''UploadViewModel' (HashCode=33902366)'.
System.Windows.Data错误:40:BindingExpression路径错误:在“对象”“ UploadViewModel”(HashCode = 33902366)“上找不到“ UploadObject”属性。 BindingExpression:Path=UploadObject.UploadProgress;
BindingExpression:Path = UploadObject.UploadProgress; DataItem='UploadViewModel' (HashCode=33902366);
DataItem ='UploadViewModel'(HashCode = 33902366); target element is 'ProgressBar' (Name='');
目标元素是'ProgressBar'(Name =''); target property is 'Value' (type 'Double')
目标属性为“值”(类型为“双精度”)
You need to make declare the scope of the property to public , or it will be private by default. 您需要将属性的范围声明为public ,否则默认为私有。 Hence it was not visible when binding.
因此,绑定时不可见。
public UploadInitiation UploadObject { get; set; } = new UploadInitiation();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.