活动处理程序不在XAML工作



我的页面中有一个TextBox。有INotifyChangeProperty

所有事件处理程序(LostFocus,KeyDown,KeyUp)都不会发射。在XAML后面我有C#代码。

private void TextBox_KeyUp_For_Decimal(object sender, KeyEventArgs e)
{
}

这是XAML代码

<Grid Visibility="{Binding FreeInput, Converter={StaticResource  BoolToVisibilityConverter}}">
   <Grid.Resources>
      <TextBox 
         x:Key="StringDefaultPresenter" 
         x:Shared="False" 
         Text="{Binding Default, UpdateSourceTrigger=LostFocus}" CommandManager.PreviewExecuted="TextBox_PreviewExecuted" 
         LostFocus="Update_Default" 
         KeyDown="TextBox_KeyDown_For_String"/>
      <TextBox 
         x:Key="NumberDefaultPresenter" 
         x:Shared="False" 
         Text="{Binding Default, UpdateSourceTrigger=LostFocus}"
         CommandManager.PreviewExecuted="TextBox_PreviewExecuted" 
         LostFocus="Update_Default" 
         KeyDown="TextBox_KeyDown_For_Decimal" 
         KeyUp="TextBox_KeyUp_For_Decimal"/>
      <CheckBox 
         x:Key="BooleanDefaultPresenter" 
         x:Shared="False" 
         HorizontalAlignment="Center" 
         VerticalAlignment="Center" 
         LostFocus="Update_Default" 
         IsChecked="{Binding Default, Converter={l:DefaultValueConverter}, UpdateSourceTrigger=LostFocus}"/>
      <DatePicker 
         x:Key="DateTimeDefaultPresenter" 
         x:Shared="False" 
         SelectedDate="{Binding Default, Converter={l:DefaultValueConverter}, UpdateSourceTrigger=LostFocus}" 
         LostFocus="Update_Default"/>
      <Style x:Key="DefaultPresenterStyle" x:Shared="False" TargetType="ContentControl">
         <Style.Triggers>
            <DataTrigger Binding="{Binding DataType}" Value="{x:Static l:DataType.STRING}">
               <Setter Property="Content" Value="{StaticResource StringDefaultPresenter}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding DataType, Converter={l:EnumMatchToBoolConverter}, ConverterParameter={StaticResource NumberDataType}}" Value="True">
               <Setter Property="Content" Value="{StaticResource NumberDefaultPresenter}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding DataType}" Value="{x:Static l:DataType.BOOLEAN}">
               <Setter Property="Content" Value="{StaticResource BooleanDefaultPresenter}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding DataType}" Value="{x:Static l:DataType.DATE_TIME}">
               <Setter Property="Content" Value="{StaticResource DateTimeDefaultPresenter}"/>
            </DataTrigger>
         </Style.Triggers>
      </Style>
   </Grid.Resources>
   <ContentControl Style="{StaticResource DefaultPresenterStyle}"/>
</Grid>

这是在我添加文本框和添加样式的x:键之前的工作。

找到了问题。某种程度上,由于XAML虚拟化,处理程序未连接到事件上。使用样式明确地解决问题。

喜欢将其添加到文本框或在这种情况下为Combobox

      <ComboBox
         x:Key="StringLengthPresenter" x:Shared="False"
         SelectedItem="{Binding Length, UpdateSourceTrigger=PropertyChanged}">
         <ComboBox.Style>
           <Style TargetType="ComboBox">
             <EventSetter Event="SelectionChanged" Handler="Length_SelectionChanged"/>
           </Style>
         </ComboBox.Style>

相关内容

  • 没有找到相关文章

最新更新