我正在尝试将命令绑定到视图模型,但它没有触发
xmlns:ViewModel="clr-namespace:Lister.WPF.ViewModels"
DataContext="{Binding ViewModel:TweetViewModel}" Icon="pack://siteoforigin:,,,/Resources/internet_down_16_hot.png" Loaded="Window_Loaded">
<Grid>
<!--Test-->
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem BorderThickness="5" Header="Status">
<MenuItem BorderThickness="5" Header="Timeline" Command="{Binding RefreshTweetsCommand}"/>
以下是VM的代码
private RelayCommand _refreshTweetsCommand;
public RelayCommand RefreshTweetsCommand
{
get
{
return _refreshTweetsCommand ??
(_refreshTweetsCommand =
new RelayCommand(RefreshTweetList, LoadTweets));
}
}
答案 0 :(得分:2)
DataContext="{Binding ViewModel:TweetViewModel}"
这无法绑定DataContext
。
按如下方式设置DataContext:
<Window>
<Window.DataContext>
<ViewModel:TweetViewModel/>
</Window.DataContext>
</Window>