【发布时间】:2010-11-25 22:21:51
【问题描述】:
感谢this question (click me!),我将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 并可以在标记中声明?
【问题讨论】:
标签: wpf data-binding xaml mvvm webbrowser-control