[英]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.