[UWP] AppBarButton点击事件并不总是触发

人气:560 发布:2022-09-22 标签: wpdevelop

问题描述

我的主窗口TopAppBar.CommandBar中有一些AppBarButtons。我正在使用PathIcon来定义AppBarButton.Icon。我遇到的问题是,如果鼠标从控件的底部进入按钮,该按钮将仅变为活动状态或突出显示。只有当按钮处于突出显示状态时,才会触发click事件。就描述按钮而言,我没有什么特别的。

< CommandBar x:Name =" cmdBarMain" 背景="透明"  FlowDirection =" RightToLeft" OverflowButtonVisibility = QUOT;折叠" IsDynamicOverflowEnabled = QUOT假QUOT; Horizo​​ntalContentAlignment = QUOT;右"> < CommandBar.Content> < TextBlock x:Name =" tbProfile"余量= QUOT; 12,14"的Horizo​​ntalAlignment = QUOT;中心"前景= QUOT;黑色" /> < /CommandBar.Content>  < AppBarToggleButton x:Uid =" ScrollLock"点击= QUOT; BtnScrollLock_Checked" X:名称= QUOT; btnScrollLock" Grid.Column = QUOT 1 QUOT;前景= QUOT;#FF43434E" ToolTipService.ToolTip =" Scroll lock"能见度= QUOT;折叠"> < AppBarToggleButton.Icon> < PathIcon Horizo​​ntalAlignment =" Center" VerticalAlignment = QUOT;中心"数据= QUOT; M10,13.0624961853027L8.46093940734863,13.546875 7.98730516433716,14.0644540786743 7.8125,14.6875 8.4375,15.828125 10,16.3125038146973 11.5390682220459,15.828125 12.1875,14.6875 11.5390682220459,13.546875 10,13.0624961853027z M10,1.49999618530273L8.63575077056885,1.70800352096558 7.52345085144043,2.27343320846558 6.77442932128906, 3.10839629173279 6.50001525878906,4.12500381469727 6.50001525878906,6.3749885559082 13.4375,6.3749885559082 13.4375,4.1874885559082 13.1992206573486,3.13475704193115 12.4687528610229,2.28124380111694 11.3632831573486,1.708979845047 10,1.49999618530273z M10,0L12.1250066757202,0.329101383686066 13.8750095367432,1.22656106948853 15.0625114440918,2.55761241912842 15.5000114440918,4.1874885559082 15.5000114440918,6.43749237060547 19.9375152587891,6.43749237060547 20, 6.9999885559082 20,19.0625 0,19.0625 0,6.93750381469727 0.0625038146972656,6.3749885559082 4.50000762939453,6.3749885559082 4.50000762939453,4.1874885559082 4.93750762939453,2.55761241912842 6 .12500667572021,1.22656106948853 7.87500429153442,0.329101383686066 10,0z" /> < /AppBarToggleButton.Icon> < / AppBarToggleButton> < AppBarButton x:Name =" btnFullScreen" Grid.Column = QUOT; 3英寸前景= QUOT;#FF43434E" X:UID ="全屏"点击= QUOT; btnFullScreen_Click"> < AppBarButton.Icon> < PathIcon Horizo​​ntalAlignment =" Center" VerticalAlignment = QUOT;中心"数据= QUOT; M7.24122524261475,11.8743715286255L8.12497425079346,12.7581186294556 2.13421630859375,18.7500019073486 6.24999046325684,18.7500019073486 6.24999046325684,20 0,20 0,13.7500085830688 1.24999821186066,13.7500085830688 1.24999821186066,17.8667221069336 7.24122524261475,11.8743715286255z M12.758768081665,11.8743562698364L18.7499713897705,17.8667259216309 18.7499713897705 ,13.7500085830688 19.9999694824219,13.7500085830688 19.9999694824219,20 13.749979019165,20 13.749979019165,18.7500019073486 17.8657779693604,18.7500019073486 11.8749809265137,12.7581043243408 12.758768081665,11.8743562698364z M13.749979019165,0L19.9999694824219,0 19.9999694824219,6.24999046325684 18.7499713897705,6.24999046325684 18.7499713897705,2.1332311630249 12.7587175369263,8.12564182281494 11.8749685287476,7.24188899993896 17.8657054901123, 1.24999821186066 13.749979019165,1.24999821186066 13.749979019165,0z M0,0L6.24999046325684,0 6.24999046325684,1.24999821186066 2.13426518440247,1.24999821186066 8.12500190 734863,7.24188899993896 7.24125289916992,8.12564182281494 1.24999821186066,2.13323163986206 1.24999821186066,6.24999046325684 0,6.24999046325684 0,0z" /> < /AppBarButton.Icon> < / AppBarButton> < AppBarButton x:Name =" btnOpenMenu" Grid.Column = QUOT; 0"前景= QUOT;#FF43434E"点击= QUOT; btnOpenMenu_Click"> < AppBarButton.Icon> < PathIcon Horizo​​ntalAlignment =" Center" VerticalAlignment = QUOT;中心"数据= QUOT; M0,16.6949424743652L19.9960536956787,16.6949424743652 19.9960536956787,20 0,20 0,16.6949424743652z M0,8.34812831878662L19.9960536956787,8.34812831878662 19.9960536956787,11.6531858444214 0,11.6531858444214 0,8.34812831878662z M0,0L19.9960536956787,0 19.9960536956787,3.30505657196045 0,3.30505657196045 0,0z" /> < /AppBarButton.Icon> < / AppBarButton>  < / CommandBar> 

解决方案

< blockquote>

吉姆,你好b $ b >>我遇到的问题是,只有当鼠标从控件底部进入按钮时,按钮才会变为活动状态或突出显示。 抱歉,我无法重现这个问题在我的项目中,我测试了你的代码,实际的结果是无论鼠标进入哪一侧,按钮都会突出显示,每次点击事件都可以触发,所以我担心你需要提供更多详细信息,如作为您的操作系统,Visual Studio版本和项目的目标版本。 如果您能提供一个简单的演示来重现您的问题,那就更好了。 感谢您的理解。 问候,

Barry

I have some AppBarButtons in my main window TopAppBar.CommandBar. I'm using PathIcon to define the AppBarButton.Icon. The problem I am having is that the button will only become active or highlighted if the mouse entered into the button from the bottom of the control. The click event will only fire if the button is in the highlighted state. There is nothing special that I'm doing as far as describing the buttons.

       <CommandBar  x:Name="cmdBarMain"  
                     Background="Transparent"
                     FlowDirection="RightToLeft" OverflowButtonVisibility="Collapsed" IsDynamicOverflowEnabled="False" HorizontalContentAlignment="Right">
            <CommandBar.Content>
                <TextBlock x:Name="tbProfile" Margin="12,14" HorizontalAlignment="Center" Foreground="Black"/>
            </CommandBar.Content>
            
            <AppBarToggleButton x:Uid="ScrollLock" Click="BtnScrollLock_Checked" x:Name="btnScrollLock" Grid.Column="1" Foreground="#FF43434E" ToolTipService.ToolTip="Scroll lock" Visibility="Collapsed">
                        <AppBarToggleButton.Icon>
                            <PathIcon HorizontalAlignment="Center" VerticalAlignment="Center" Data="M10,13.0624961853027L8.46093940734863,13.546875 7.98730516433716,14.0644540786743 7.8125,14.6875 8.4375,15.828125 10,16.3125038146973 11.5390682220459,15.828125 12.1875,14.6875 11.5390682220459,13.546875 10,13.0624961853027z M10,1.49999618530273L8.63575077056885,1.70800352096558 7.52345085144043,2.27343320846558 6.77442932128906,3.10839629173279 6.50001525878906,4.12500381469727 6.50001525878906,6.3749885559082 13.4375,6.3749885559082 13.4375,4.1874885559082 13.1992206573486,3.13475704193115 12.4687528610229,2.28124380111694 11.3632831573486,1.708979845047 10,1.49999618530273z M10,0L12.1250066757202,0.329101383686066 13.8750095367432,1.22656106948853 15.0625114440918,2.55761241912842 15.5000114440918,4.1874885559082 15.5000114440918,6.43749237060547 19.9375152587891,6.43749237060547 20,6.9999885559082 20,19.0625 0,19.0625 0,6.93750381469727 0.0625038146972656,6.3749885559082 4.50000762939453,6.3749885559082 4.50000762939453,4.1874885559082 4.93750762939453,2.55761241912842 6.12500667572021,1.22656106948853 7.87500429153442,0.329101383686066 10,0z" />
                        </AppBarToggleButton.Icon>
                    </AppBarToggleButton>
                    <AppBarButton x:Name="btnFullScreen" Grid.Column="3" Foreground="#FF43434E" x:Uid="FullScreen"  Click="btnFullScreen_Click">
                        <AppBarButton.Icon>
                            <PathIcon HorizontalAlignment="Center" VerticalAlignment="Center" Data="M7.24122524261475,11.8743715286255L8.12497425079346,12.7581186294556 2.13421630859375,18.7500019073486 6.24999046325684,18.7500019073486 6.24999046325684,20 0,20 0,13.7500085830688 1.24999821186066,13.7500085830688 1.24999821186066,17.8667221069336 7.24122524261475,11.8743715286255z M12.758768081665,11.8743562698364L18.7499713897705,17.8667259216309 18.7499713897705,13.7500085830688 19.9999694824219,13.7500085830688 19.9999694824219,20 13.749979019165,20 13.749979019165,18.7500019073486 17.8657779693604,18.7500019073486 11.8749809265137,12.7581043243408 12.758768081665,11.8743562698364z M13.749979019165,0L19.9999694824219,0 19.9999694824219,6.24999046325684 18.7499713897705,6.24999046325684 18.7499713897705,2.1332311630249 12.7587175369263,8.12564182281494 11.8749685287476,7.24188899993896 17.8657054901123,1.24999821186066 13.749979019165,1.24999821186066 13.749979019165,0z M0,0L6.24999046325684,0 6.24999046325684,1.24999821186066 2.13426518440247,1.24999821186066 8.12500190734863,7.24188899993896 7.24125289916992,8.12564182281494 1.24999821186066,2.13323163986206 1.24999821186066,6.24999046325684 0,6.24999046325684 0,0z" />
                        </AppBarButton.Icon>
                    </AppBarButton>
            <AppBarButton x:Name="btnOpenMenu" Grid.Column="0" Foreground="#FF43434E" Click="btnOpenMenu_Click">
                <AppBarButton.Icon>
                    <PathIcon HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0,16.6949424743652L19.9960536956787,16.6949424743652 19.9960536956787,20 0,20 0,16.6949424743652z M0,8.34812831878662L19.9960536956787,8.34812831878662 19.9960536956787,11.6531858444214 0,11.6531858444214 0,8.34812831878662z M0,0L19.9960536956787,0 19.9960536956787,3.30505657196045 0,3.30505657196045 0,0z" />
                </AppBarButton.Icon>
            </AppBarButton>

        </CommandBar>

解决方案

Hi Jim, >> The problem I am having is that the button will only become active or highlighted if the mouse entered into the button from the bottom of the control. Sorry I can not reproduce this issue in my project, I tested your code and the actual result is the button will be highlighted no matter which side the mouse enters, and the click event can be fired every time, so I’m afraid you need provide more details such as your operating system, Visual Studio version and the target version of your project. It would be better if you can provide a simple demo to reproduce your problem. Thanks for your understanding. Regards,

Barry

779