Команда не выполняется из viewmodel WPF
Click on hyperlink not executing Click() method of Viewmodel through delegate command. Datacontext is: DataContext = new DocumentsViewModel(); What I am missing here, please help me.
Что я уже пробовал:
Дерево:
<TreeView Name="trvMenu" ItemsSource="{Binding ReportPeriods}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate DataType="{x:Type self:dcsReportingPeriod}" ItemsSource="{Binding Path=ChildReports}"> <TextBlock Text="{Binding Name}" /> <HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <TextBlock> <Hyperlink Command="{Binding ClickCommand}"> <TextBlock Text="{Binding Path=Name}" > <TextBlock.ContextMenu> <ContextMenu> <MenuItem Header ="PDF" ></MenuItem> </ContextMenu> </TextBlock.ContextMenu> </TextBlock> </Hyperlink> </TextBlock> </DataTemplate> </HierarchicalDataTemplate.ItemTemplate> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView>
модель представления:
public class DocumentsViewModel : NotificationObject { private ObservableCollection<dcsReportingPeriod> _reportPeriods; public ObservableCollection<dcsReportingPeriod> ReportPeriods { get { return _reportPeriods; } set { _reportPeriods = value; RaisePropertyChanged("ReportPeriods"); ClickCommand.RaiseCanExecuteChanged(); } } public DelegateCommand ClickCommand { get; set; } public DocumentsViewModel() { ClickCommand = new DelegateCommand(Click, ClickCanExecute); ReportPeriods = new ObservableCollection<dcsReportingPeriod>(); ReportPeriods = null; } public bool ClickCanExecute() { return ReportPeriods != null; } public void Click() { GeodeAssistant.OpenDocument("https://www.google.co.in", true, DocumentNavigationModes.NONE, null, GeodeLaunchModes.Right); } }