【问题标题】:Textbox binding Unable to cast object of type 'System.Reflection.RuntimeEventInfo' to type 'System.Reflection.MethodInfo'文本框绑定无法将“System.Reflection.RuntimeEventInfo”类型的对象转换为“System.Reflection.MethodInfo”类型
【发布时间】:2021-10-23 12:45:21
【问题描述】:

我想检查格式 00:00 的 TextBox 中的输入是否匹配。所以我在我的 ViewModel 中创建了一个方法:

private void MinPauseTextChanged(object sender, TextChangedEventArgs args)
{
   //check text..
}

我在 XAML 中的绑定如下所示:

<TextBox Grid.Row="0" Grid.Column="1" x:Name="TextBoxSettingMinPause" TextChanged="{Binding Path=MinPauseTextChanged}" Text="{Binding Path=MinPauseSetting}"/>

我总是收到此错误,但我不知道为什么,我按照 Microsoft 网站上的说明进行操作:https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.textchangedeventargs?view=net-5.0

这是我的错误代码: InvalidCastException:“System.Reflection.RuntimeEventInfo”类型的对象不能隐式转换为“System.Reflection.MethodInfo”。

【问题讨论】:

    标签: c# regex wpf events textbox


    【解决方案1】:

    编辑: 只需将 StringFormat 添加到您的 XAML 代码中,如下所示:

    <TextBox Grid.Row="0" Grid.Column="1" x:Name="TextBoxSettingMinPause" Text="{Binding Path=MinPauseSetting, StringFormat={}{00:00}}" />
    

    并删除方法...

    【讨论】:

      猜你喜欢
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      相关资源
      最近更新 更多