c# - 如何正确使用 DelegateCommand?
问题描述
在调试模式下,从构造函数转到set方法,但在get方法中没有任何时候进入,我认为这是问题,但我不知道如何解决。
在 .xaml 文件中,我定义了按钮。
<dx:ThemedWindow
x:Class="ProductsModule.View.ProductView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
Title="MenuView" Height="800" Width="1000">
<Grid Margin="20" VerticalAlignment="Top" Background="White" Height="420" DataContext="{Binding Detail}">
<Grid.Effect>
<DropShadowEffect BlurRadius="20" ShadowDepth="1"/>
</Grid.Effect>
<StackPanel Margin="750 70 70 70" HorizontalAlignment="Left">
<TextBlock Text="{Binding Name}" FontSize="18" Margin="0 5" Foreground="#FF6A6A6A"/>
<Button Command="{Binding ShowCommand }">Add data</Button>
</StackPanel>
</Grid>
</dx:ThemedWindow>
在 .xaml.cs 文件中,我定义了数据上下文。
public SecondView()
{
InitializeComponent();
this.DataContext = new ViewModel();
}
查看模型
public ViewModel()
{
ShowCommand = new DelegateCommand(ShowMethod);
}
public ICommand ShowCommand
{
get;
set;
}
private void ShowMethod()
{
OrderView orderView = new OrderView();
orderView.Show();
}
当我按下按钮时,不调用 ShowMethod() 并且不执行任何操作。
解决方案
推荐阅读
- php - Wordpress 管理页面不断加载
- angular - 在 HTTP 请求中发送带有上传文件的表单
- reactjs - 在graphql-request中设置firebase令牌的正确方法是什么
- php - 如何从mysql数据库中获取最后一个id
- elasticsearch - 使用聚合查找最新批次中的文件数
- r - reactiveValues() 的问题并在 R Shiny App 中观察
- mongodb - 将 DB 属性映射到猫鼬上的不同对象属性
- java - 如何将我的实体的 Instant 类型属性映射到我的 Oracle 数据库中的日期类型列?
- gradle - 配置 gradle 文件时 Pub/Sub 出错
- flutter - Flutter google map myLocation 按钮 iOS 风格