【问题标题】:How do I change the OnMouseHover behavior of an Editor Control in Xamarin.Forms如何更改 Xamarin.Forms 中编辑器控件的 OnMouseHover 行为
【发布时间】:2017-02-09 15:23:04
【问题描述】:

我正在Xamarin.Forms 中设计一个应用程序,我正在使用Editor 控件,如下所示:

我在 UWP 上运行它,当我将鼠标悬停在控件上时,背景颜色反转为黑色。见下图:

注意力不集中

鼠标悬停

专注

如你所见,非常可怕。

我感觉这可能与this ThemeResource Style有关,我在WinRT平台上也可以看到(我认为UWP使用相同的控件)it is definitely applying that style但我对Styles了解不够告诉 可能和this line in particular有关

【问题讨论】:

    标签: c# xamarin uwp xamarin.forms


    【解决方案1】:

    确实,问题出在您的预期中。在您的情况下,VisualState PointerOver 将边框画笔和背景的不透明度设置为新值。如果您想保持背景不变,只需删除下面代码中标记的部分即可。

    我可能会保持边框画笔突出显示,以便用户仍然可以看到控件已聚焦。但是,如果您愿意,您也可以删除它(实际上是整个视觉状态)。

    <VisualState x:Name="PointerOver">
      <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
          <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightChromeAltLowBrush}" />
        </ObjectAnimationUsingKeyFrames>
    
        <!-- Remove the following -->
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement">
          <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}" />
        </ObjectAnimationUsingKeyFrames>
        <!-- until here -->
    
      </Storyboard>
    </VisualState>
    

    【讨论】:

    • 这意味着拥有Xamain.Forms 的自定义构建有没有办法可以在我的App.xaml 中设置TextControlBackgroundHoverOpacity 的值来改变行为?
    • @user1 对,没有意识到这是 Xamarin.Forms 的内部代码。然后我会在 UWP 特定代码中更新 TextControlBackgroundHoverOpacity 的值。像这样的东西:Windows.UI.Xaml.Application.Current.Resources["TextControlBackgroundHoverOpacity"] = 1;您也可以通过编程方式删除 VisualState,但我正在打电话,现在无法验证。
    • xaml中的资源可以替换吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    相关资源
    最近更新 更多