Custom Controls
MainPage.xaml
Windows Store 2017
<Page
x:Class="Demo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Demo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<local:MyUserControl1 HorizontalAlignment="Left" Margin="275,282,0,0" VerticalAlignment="Top" Height="193" Width="531"/>
</Grid>
</Page>
MyUserControl1.xaml
Windows Store 2017
<UserControl x:Class="Demo.MyUserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Demo" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid Background="Maroon" Margin="0,0,-45,0"> <Grid.Resources> <Style TargetType="TextBlock"> <Setter Property="FontSize" Value="24"></Setter> <Setter Property="HorizontalAlignment" Value="Center"></Setter> <Setter Property="VerticalAlignment" Value="Center"></Setter> </Style> </Grid.Resources> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Text="UserName: " Grid.Row="0" Grid.Column="0"></TextBlock> <TextBlock Text="Password: " Grid.Row="1" Grid.Column="0"></TextBlock> <TextBox Name="txtUserName" Grid.Row="0" Grid.Column="1" Width="200" Height="30"></TextBox> <PasswordBox Name="txtPassword" Grid.Row="1" Grid.Column="1" Width="200" Height="30"></PasswordBox> <Button Grid.ColumnSpan="2" HorizontalAlignment="Center" Grid.Row="2" Content="Login" Click="Button_Click"></Button> </Grid> </UserControl>
MyUserControl1.xaml.cs
Windows Store 2017
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236 namespace Demo { public sealed partial class MyUserControl1 : UserControl { public MyUserControl1() { this.InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { ((Frame)Window.Current.Content).Navigate(typeof(MainPage)); } } }
Run app test
0 nhận xét:
Post a Comment