如何通过单击进入 ItemsControl MVVM 来更改 TextBlock 的数据绑定?

How to change databinding of TextBlock by Click into ItemsControl MVVM?

如何单击 1 ItemsControl 然后它更改值文本但不起作用

这是我在视图中的代码 xaml:

<ItemsControl ItemsSource="{Binding FCsource}">
    <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border Margin="10" Width="440" Height="220" >
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="MouseLeftButtonDown">
                                                    <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}, Path=DataContext.MouseLeftButtonDown }" >
                                                    </i:InvokeCommandAction>
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                            <Grid>
                                                <TextBlock Text="{Binding Words}"></TextBlock>
                                            </Grid>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
    </ItemsControl>

这是我在 ViewModel 中的代码 xaml:

public ObservableCollection _FCsource;

public ObservableCollection<Model.MenuItem> FCsource { get { return AddFlashCard(); } set { FCsource = value; OnPropertyChanged(); } }

private String _Words;
public string Words { get => _Words; set { _Words = value; OnPropertyChanged(); } }

public RelayCommand MouseLeftButtonDown { get; set; }

public WordsViewModel()
{
    MouseLeftButtonDown = new RelayCommand(() => MessageBox.Show("Message", "Hi"));
}

private ObservableCollection<MenuItem> AddFlashCard()
{
    ObservableCollection<MenuItem> listmn = new ObservableCollection<MenuItem>();
    listmn.Add(new MenuItem("qwda"));
    listmn.Add(new MenuItem("qwda"));
    return listmn;
}

如何在您的 DataTemplate 中编写一个简单的按钮,然后将您的 TextBlock 放入其中:

<Button Command="YourRelayCommand">
    <TextBlock Text="{Binding Words}" />
</Button>