首页 > 解决方案 > 每次运行 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>

标签: uwpuwp-xaml

解决方案


您正在处理GotFocus事件(

<Core:EventTriggerBehavior EventName="GotFocus" ..>

) 这意味着每次TextBox聚焦时都会调用您的命令。您可以尝试处理另一个事件,例如PointerEnteredTapped


推荐阅读