How to create transparent command bar in Windows Phone 8.1

末鹿安然 提交于 2019-12-11 08:09:24

问题


how to create transparent command bar in Windows Phone 8.1 Here is xaml

<Page x:Class="App3.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"      
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  Background="White"      
  mc:Ignorable="d">

<Grid Background="Red" />

<Page.BottomAppBar>
    <CommandBar Background="#CCFFFFFF" Foreground="Black">
        <CommandBar.PrimaryCommands>
            <AppBarButton Label="Button1" />
        </CommandBar.PrimaryCommands>
    </CommandBar>
</Page.BottomAppBar>

When CommandBar is open, it has a transparent background, but there is a white panel behind. Hot to remove this panel?


回答1:


Use this code in App.xaml.cs, OnLaunched Method, before Window.Current.Activate();

Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SetDesiredBoundsMode(
ApplicationViewBoundsMode.UseCoreWindow);

EDIT : Bydefault, the framework layouts the window's content within the visible region only. Hence, when you expanded the appbar, it shows the basecolor(black/white) behind it eventhough you set the appbar transparent. So if you want to make use of entire page window, you have to use the above code, which sets core window across the entire app.




回答2:


By changing the opacity you can make the commandbar transparent or add an x:Name to commandbar if you want to change background to tranparent

<CommandBar Background="#CCFFFFFF" Foreground="Black" x:name="op" opacity=0.4>
//and in the code
//add 
op.Background = new SolidnewBrush(Windows.UI.Colors.Transparent);`


来源:https://stackoverflow.com/questions/24523833/how-to-create-transparent-command-bar-in-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!