Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何卸下按钮';按下时的背景色-xamarin形成UWP_Xamarin_Xamarin.forms_Uwp - Fatal编程技术网

如何卸下按钮';按下时的背景色-xamarin形成UWP

如何卸下按钮';按下时的背景色-xamarin形成UWP,xamarin,xamarin.forms,uwp,Xamarin,Xamarin.forms,Uwp,我想在按下按钮时删除按钮的背景色,并希望有透明背景,因为我使用图像作为背景。 通过以下代码,可以在鼠标悬停时删除边框: btn.BorderThickness = new Thickness(0,0,0,0); btn.Padding = new Thickness(0, 0, 0, 0); 通过设置: btn.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent); 但是,我

我想在按下按钮时删除按钮的背景色,并希望有透明背景,因为我使用图像作为背景。
通过以下代码,可以在鼠标悬停时删除边框:

btn.BorderThickness = new Thickness(0,0,0,0);
btn.Padding = new Thickness(0, 0, 0, 0);
通过设置:

btn.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent);
但是,我无法在单击背景时删除它,它显示的是灰色背景。

任何建议都将不胜感激。

无论您设置了什么,由于按下了
CommonState的
状态,将(应该)覆盖您的值

<VisualState x:Name="Pressed">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid"
                                       Storyboard.TargetProperty="Background">
            <!-- This will cause the gray background color of the button -->
            <DiscreteObjectKeyFrame
                KeyTime="0"
                Value="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>


与其从代码隐藏中设置颜色以及边框,还不如为按钮创建自己的模板,将
背景设置为所需的值,例如
透明

是否尝试过targetButton.BackgroundColor=color.Transparency已找到它,移除了故事板本身。谢谢though@Sudha您可以批准答案,或关闭问题:)@Herdo是否有办法通过样式等删除所有按钮的背景?@Shimmy当然,只需设置按钮的默认样式。