我必须跟随ProgressIndicator
<MahAppsControls:ProgressIndicator Width="100"
Height="10"
VerticalAlignment="Center"
ProgressColour="White"
Visibility="{Binding ProgressVisibility}"/>
并在与此视图相关的 ViewModel 中实现
private Visibility progressVisibility = Visibility.Collapsed;
public Visibility ProgressVisibility
{
get { return progressVisibility; }
set
{
if (value == progressVisibility)
return;
progressVisibility = value;
this.OnPropertyChanged("ProgressVisibility");
}
}
问题是这个绑定失败了,我不知道为什么。使用 Snoop 我有以下内容
System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“ProgressIndicator”(名称=“progressIndicator”)上找不到“ProgressVisibility”属性。BindingExpression:Path=ProgressVisibility; DataItem='ProgressIndicator'(名称='progressIndicator');
目标元素是'ProgressIndicator'(名称='progressIndicator');目标属性是“可见性”(类型“可见性”) System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“ProgressIndicator”(名称=“progressIndicator”)上找不到“ProgressVisibility”属性。BindingExpression:Path=ProgressVisibility; DataItem='ProgressIndicator'(名称='progressIndicator');
目标元素是'ProgressIndicator'(名称='progressIndicator');目标属性是“可见性”(类型“可见性”) System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“ProgressIndicator”(名称=“progressIndicator”)上找不到“ProgressVisibility”属性。BindingExpression:Path=ProgressVisibility; DataItem='ProgressIndicator'(名称='progressIndicator');
目标元素是'ProgressIndicator'(名称='progressIndicator');目标属性是“可见性”(类型“可见性”)
我很欣赏存在绑定错误,但我DataContext
在 App.xaml.cs 中设置了主窗口
MainWindow window = new MainWindow();
MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();
// When the ViewModel asks to be closed, close the window.
EventHandler handler = null;
handler = delegate
{
mainWindowViewModel.RequestClose -= handler;
window.Close();
};
mainWindowViewModel.RequestClose += handler;
// Allow all controls in the window to bind to the ViewModel by setting the
// DataContext, which propagates down the element tree.
window.DataContext = mainWindowViewModel;
window.Show();
那么,为什么绑定失败?
谢谢你的时间。