感谢这个问题(点击我!)让我正确地将我的 WebBrowser
的 Source
属性绑定到了我的 ViewModel。
现在,我想实现两个目标:
- 使我的后退和前进按钮的
IsEnabled
属性正确地绑定到WebBrowser
的CanGoBack
和CanGoForward
属性上。 - 找出如何调用
GoForward()
和GoBack()
方法,而不必诉诸于代码后台,也不必让 ViewModel 知道WebBrowser
的存在。
我目前拥有以下(不起作用的)XAML 标记:
<WebBrowser
x:Name="_instructionsWebBrowser"
x:FieldModifier="private"
clwm:WebBrowserUtility.AttachedSource="{Binding InstructionsSource}" />
<Button
Style="{StaticResource Button_Style}"
Grid.Column="2"
IsEnabled="{Binding ElementName=_instructionsWebBrowser, Path=CanGoBack}"
Command="{Binding GoBackCommand}"
Content="< Back" />
<Button
Style="{StaticResource Button_Style}"
Grid.Column="4"
IsEnabled="{Binding ElementName=_instructionsWebBrowser, Path=CanGoForward}"
Command="{Binding GoForwardCommand}"
Content="Forward >" />
我相当确定问题是因为CanGoBack
和CanGoForward
不是依赖属性(也没有实现INotifyChanged
),但我不太确定如何解决这个问题。
问题:
有没有办法连接附加属性(就像我使用
Source
那样)或类似的东西来使CanGoBack
和CanGoForward
绑定正常工作?如何编写
GoBackCommand
和GoForwardCommand
,使它们独立于代码和ViewModel,并可以在标记中声明?