uwp - 每次运行 UWP 命令而不是 onclick 事件
问题描述
我有一个登录页面。
用户登录后,它将重定向到包含所选城市文本框的页面。单击它时,它将显示一个城市列表。
我已经使用 uwp 中的命令编写了 onclick 事件。每次登录成功后都会调用。我不知道为什么会这样?
我只为 onclick 事件编写了它:
<TextBlock Text="community" x:Uid="SelectCommunity" FontSize="15" Foreground="Black" TextAlignment="Left" Margin="10,8,38,70" Grid.ColumnSpan="2" Grid.RowSpan="2" />
<TextBlock Text="*" Foreground="Red" Grid.Column="1" TextAlignment="Right" Margin="0,10,38,70" Grid.RowSpan="2"/>
<TextBox Visibility="Collapsed" Text="{Binding _common[0].Community_Name}" Background="Yellow" BorderBrush="#c0c0c0" Foreground="Black" Name="txtcommunity" FontSize="15" Margin="0,10.333,34,0" Grid.Row="1">
</TextBox>
<TextBox Text="{Binding _common[0].Community_Name,Mode=TwoWay}" IsReadOnly="True" Background="Yellow" BorderBrush="#c0c0c0" Foreground="Black" FontSize="13" Margin="10,10.333,38,25" Grid.Row="1" Grid.ColumnSpan="2">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="GotFocus">
<Core:InvokeCommandAction Command="{Binding DataContext.CommunityCmd,ElementName=Sectors,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" CommandParameter="{Binding ElementName=txtcommunity}" ></Core:InvokeCommandAction>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
解决方案
您正在处理GotFocus
事件(
<Core:EventTriggerBehavior EventName="GotFocus" ..>
) 这意味着每次TextBox
聚焦时都会调用您的命令。您可以尝试处理另一个事件,例如PointerEntered
或Tapped
。
推荐阅读
- javascript - jQuery 不会在 IE 上运行,普通的 JS 也不会
- visual-studio-2017 - 如何将代码分析错误 CA1506 类耦合更改为“中等可维护性”
- firebase - 无法从 3.19.1 更新 firebase 工具
- c# - c# asp.net网站调用一个webApi
- html - 总表/容器中的第 n 个孩子
- python-3.x - 通过 GeckoDriver Firefox 和 Selenium 执行测试时出现“线程在处理恐慌时出现恐慌。中止”错误
- powerbi - 如何使用 Power BI 在所有列中查找和替换
- java - 如何检查数字是否存在 JSON 字符串?
- vuejs2 - 将元素ui导入nuxt时出现样式错误
- javascript - 反应——在反应中添加输入切换