简体   繁体   English

如何允许Windows商店应用程序的用户更改界面

[英]How to allow user change interface of Windows store application

Consider this Example code 考虑这个示例代码

        <Grid Name="MyParentGrid">

        <Grid.Background>
            <ImageBrush ImageSource="Test.jpg"/>
        </Grid.Background>

            <HyperlinkButton Name="Play" Click="Play_Click" Background="Black"/>
            <HyperlinkButton Name="Personalize"Click="Personalize_Click" Background="Black"/>
            <HyperlinkButton Name="LeaderBoard" Click="LeaderBoard_Click" Background="Black"/>

        </Grid>

All I have now is three buttons inside a grid that has a background which is a photo. 我现在所拥有的只是网格内部的三个按钮,该网格的背景是照片。

Now If I Want to let the user when Click on a Button to View another Background instead of Test.jpg , also change the Buttons Background colors, 现在,如果我想让用户在单击按钮以查看另一个背景而不是Test.jpg ,还可以更改按钮的背景颜色,

In my source code I have a lot of grids, a lot of canvas inside them a lot of hyberlinkbuttons and sliders... etc, a lot of colors, Margins "places of this buttons" and properties and content need to be changed when the user change them by choosing another interface 在我的源代码中,我有很多网格,里面有很多画布,还有许多hyberlinkbutton和滑块...等等,很多颜色,当需要更改边框时,必须更改边距“此按钮的位置”以及属性和内容用户通过选择另一个界面来更改它们

I tried to make multiple grids "ParentGrid1" and "ParentGrid2" then start to change visibility of each, and a lot of copied and paste code "spaghetti code", How can I allow the user to change the interface totally by clicking button with good written code?? 我试图制作多个网格“ ParentGrid1”和“ ParentGrid2”,然后开始更改每个网格的可见性,并复制并粘贴了大量代码“ spaghetti code”,如何允许用户通过单击按钮完全改变界面书面代码?

For illustration, I modified your xaml: 为了说明,我修改了您的xaml:

<Grid Name="MyParentGrid">
        <Grid.Background>
            <ImageBrush ImageSource="ms-appx:///Assets/Test.jpg"/>
        </Grid.Background>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <HyperlinkButton Name="Play" Click="Play_Click" Background="Black" Content="Play"/>
            <HyperlinkButton Name="Personalize" Click="Personalize_Click" Background="Black" Content="Personalize"/>
            <HyperlinkButton Name="LeaderBoard" Click="LeaderBoard_Click" Background="Black" Content="Leaderboard"/>
        </StackPanel>
    </Grid>

And did the following in the code behind: 并在后面的代码中执行了以下操作:

    private static BitmapImage first;
    private static BitmapImage second;
    private static ImageBrush backBrush;

    public MainPage()
    {
        this.InitializeComponent();
        first = new BitmapImage(new Uri("ms-appx:///Assets/Test.jpg"));
        second = new BitmapImage(new Uri("ms-appx:///Assets/NewBackground.jpg"));

        backBrush = new ImageBrush();
        SetBackground();
    }

    private void SetBackground()
    {
        if(backBrush.ImageSource == first)
        {
            backBrush.ImageSource = second;
        }
        else
        {
            backBrush.ImageSource = first;
        }

        MyParentGrid.Background = backBrush;
    }

    private void Personalize_Click(object sender, RoutedEventArgs e)
    {
        SetBackground();
    }

The first two (Type BitmapImage) are used to represent the different background images. 前两个(类型BitmapImage)用于表示不同的背景图像。 And the third is a brush that will be used to set the Background property of the Grid. 第三个是用于设置Grid的Background属性的画笔。 Each one is initialized in the constructor. 每个都在构造函数中初始化。 The SetBackground() method simply switches to the second image if the current background image is the first and switches to the second otherwise. 如果当前背景图像是第一个,则SetBackground()方法仅切换到第二个图像,否则,切换到第二个图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows Store应用程序中进行治疗时如何阻止用户界面 - How to block the user interface while doing a treatment in a windows store app 如何区分用户输入,但允许应用程序本身更改文本 - How to distinguish between user input, but allow the application itself to change text 如何在c#代码中更改windows store应用程序的背景图像? - how to change background image of windows store application in c# code? 该应用程序调用了一个为不同线程编组的接口 - Windows Store App - The application called an interface that was marshalled for a different thread - Windows Store App 如何允许我的应用程序在 Windows 启动时运行(或更好的用户登录)而不会被 vista/7 阻止 - How to allow my application to run on Windows startup (or better, user login) without getting blocked from vista/7 如何在Windows应用程序中为当前登录的用户存储用户设置(用户名,密码) - How to store user settings (username, password) in a Windows application for the current logged in user 如何在Visual Studio中为Windows计算机的Xamarin应用程序设计用户界面? - How do I design the user interface in Visual Studio for a Xamarin application with a Windows computer? 如何在Windows 8中重新启动Windows Store应用程序 - How to restart Windows Store application in Windows 8 如何允许用户更改列表框顺序 - How to allow user to change list box order 如何允许用户更改下载路径? - How to allow user to change download path?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM