通过 xaml 中的按钮单击更新数据网格

update datagrid from a button click in xaml

我有代码隐藏

private void Button_Click(object sender, RoutedEventArgs e)
{
    this.categoriesDataGrid.Items.Refresh();
}

按钮名称是"SaveButton"。我想在 xaml 代码中这样做。我认为使用触发器或行为甚至混合资产窗格是可行的,但我尝试不成功。 谢谢

我完成了 Blend Actions

<Window.Triggers>
    <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button"/>
</Window.Triggers>

<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="108,150,0,0" VerticalAlignment="Top" Width="75" Command="{Binding SaveCommand}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <ei:CallMethodAction TargetObject="{Binding Items, ElementName=categoriesDataGrid}" MethodName="Refresh"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
</Button>`