我正在为我的 WPF 应用程序使用 AvalonDock,并希望使用数据绑定来更改主题。
视图模型:
private Theme _AvalonDockTheme = new ExpressionDarkTheme();
public Theme AvalonDockTheme
{
get
{
return _AvalonDockTheme;
}
set
{
if (_AvalonDockTheme != value)
{
_AvalonDockTheme = value;
RaisePropertyChanged("AvalonDockTheme");
}
}
}
XAML:
<xcad:DockingManager AllowMixedOrientation="True"
Theme="{Binding Source={StaticResource DockTheme}}"
x:Name="_dockingManager">
<!-- some content -->
</xcad:DockingManager>
当我使用它时,我收到以下错误消息:
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='Xceed.Wpf.AvalonDock.Themes.ExpressionDarkTheme' BindingExpression:Path=MainViewModel.AvalonDockTheme; DataItem='App' (HashCode=47182344); target element is 'CollectionViewSource' (HashCode=42887454); target property is 'Source' (type 'Object')
我不明白为什么绑定失败。绑定源和目标都是 Xceed.Wpf.AvalonDock.Themes.Theme 类型,但错误消息说目标元素是 CollectionViewSource 类型。为什么?