Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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
C# 如何以编程方式设置AppBar高度?_C#_Xaml_Windows 10_Windows 10 Mobile - Fatal编程技术网

C# 如何以编程方式设置AppBar高度?

C# 如何以编程方式设置AppBar高度?,c#,xaml,windows-10,windows-10-mobile,C#,Xaml,Windows 10,Windows 10 Mobile,我正在App.xaml.cs中创建一个全局AppBar,方法如下: public static AppBar _globalAppBar = new AppBar(); public App() { //Code SetUpBar(); } public void SetUpBar() { //SIZE _globalAppBar.Height = 250; //BACKGROUND ImageBrush bck = new ImageBr

我正在App.xaml.cs中创建一个全局AppBar,方法如下:

public static AppBar _globalAppBar = new AppBar();

public App()
{
    //Code

    SetUpBar();
}

public void SetUpBar()
{
    //SIZE
    _globalAppBar.Height = 250;

    //BACKGROUND
    ImageBrush bck = new ImageBrush();
    bck.ImageBrush = new BitmapImage(new Uri("Path"));
    _globalAppBar.Background = bck;
}
我这样实现是因为我希望这个页面出现在应用程序的每个页面中,而由提供的代码对我不起作用,所以我决定这样做(实际上是一种改编,因为在我的例子中,我使用的是C#而不是XAML)

所以,我面临的问题是appbar获取照片的大小,而我没有找到任何属性来设置ImageBrush的高度

我想设置appbar的布局,并在项目中的所有页面上共享它(避免在每个页面上复制和粘贴代码),因此非常感谢任何示例或帮助:)。
提前谢谢

正如您在评论中所说:“……但我wsd试图实现的第一个目标是使用imahe设置背景并调整其大小。”

因此,请尝试以下代码:这是示例代码:

XAML:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <Slider x:Name="slider"
                VerticalAlignment="Center"
                Maximum="250"
                Minimum="50"
                Value="100"
                ValueChanged="slider_ValueChanged"/>
</Grid>
我已将此图像设置为1600X1000分辨率

检查此屏幕截图


你可以试试。它也不起作用。我也尝试过使用调整它的大小,但该条总是以相同的方式显示。你只是想在每个地方显示相同的图像吗?或者你正在尝试在整个应用程序中创建命令栏的视觉样式?实际上不是,这是一个简单的例子。我想要一个有两个按钮的appbar:一个有下拉菜单和搜索按钮;还有一个标志。但是我想实现的第一个目标是使用imahe设置背景并调整它的大小。谢谢你的解决方案!!工作完美:)
 public static AppBar _globalAppBar = new AppBar();

    public MainPage()
    {
        this.InitializeComponent();
        SetUpBar();
    }

    public void SetUpBar()
    {
        _globalAppBar = new AppBar();
        //SIZE
        _globalAppBar.Height = 250;
        _globalAppBar.Name = "appBar";
        //BACKGROUND

        _globalAppBar.Background = new SolidColorBrush(Colors.PaleVioletRed);

        BitmapImage bmI = new BitmapImage();
        bmI= new BitmapImage(new Uri("ms-appx:///Assets/1.jpg", UriKind.RelativeOrAbsolute));

        var imageBrush = new ImageBrush();
        imageBrush.ImageSource = bmI;
        _globalAppBar.Background = imageBrush;

        AppBarButton abbtn = new AppBarButton();
        abbtn.Label = "Hello";

        _globalAppBar.Content = abbtn;
        this.TopAppBar = _globalAppBar;

    }

    private void slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
    {
        Slider sl = (Slider)sender;
        if (sl.Value!=0)
        {
            _globalAppBar.Height = sl.Value;
        }
    }