多页WPF相同组件

时间:2018-04-13 20:42:10

标签: c# wpf navigation frame

我创建了一个主窗口和2页。

页面与主页面具有相同的组件,但颜色不同。

1)是否需要检查所有组件的名称,使其与主要组件不同?

  • 由于我有错误说没有方法定义为.Close或Dragmove我将其从Optimizer.xaml
  • 中移除

2)页面不会改变:

private void Search_Click(object sender, RoutedEventArgs e)
{
    Main.Content = new Optimizer();
....}

页面设计(与主要刚改变的颜色相同):

<Page x:Class="Tool.Optimizer"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:Tool"
      mc:Ignorable="d" 
      d:DesignHeight="637" d:DesignWidth="975.5"
      Title="Optimizer">
    <Grid>
        <Grid Opacity="0.6"/>
        <Image Margin="155,0,0,0" Source="Background.jpg" Stretch="Fill" Opacity="0.8"/>
        <Grid HorizontalAlignment="Left" Width="235" Background="#FFF30909" Opacity="1
              ">
            <Button x:Name="Search" Content="&#xE71E;" HorizontalAlignment="Left" Height="33" Margin="184,252,0,0" VerticalAlignment="Top" Width="47" FontFamily="Segoe MDL2 Assets" Background="{x:Null}" FontSize="16"/>
        </Grid>
        <Image Source="Icon.ico" Stretch="Fill" RenderTransformOrigin="0.52,0.125" HorizontalAlignment="Left" Width="229" Height="132" VerticalAlignment="Top" Margin="6,0,0,0"/>
        <Grid Margin="0,0,0,597">
            <Button x:Name="Close" Content="&#xEF2C;" Height="40" VerticalAlignment="Top" Background="{x:Null}" FontFamily="Segoe MDL2 Assets" Foreground="White" HorizontalAlignment="Right" Width="40" Margin="0,0,1,0">
                <Button.BorderBrush>
                    <SolidColorBrush Color="#FF2C46BB" Opacity="0"/>
                </Button.BorderBrush>
            </Button>
            <Button x:Name="Maximize" Content="&#xEF2E;" Height="40" Margin="0,0,41,0" VerticalAlignment="Top" FontFamily="Segoe MDL2 Assets" Background="{x:Null}" Foreground="White" HorizontalAlignment="Right" Width="40" >
                <Button.BorderBrush>
                    <SolidColorBrush Color="#FF2C46BB" Opacity="0"/>
                </Button.BorderBrush>
            </Button>
            <Button x:Name="Minimize" Content="&#xEF2D;" Margin="0,0,81,0" Background="{x:Null}" FontFamily="Segoe MDL2 Assets" Foreground="White" HorizontalAlignment="Right" Width="40" Height="40" VerticalAlignment="Top">
                <Button.BorderBrush>
                    <SolidColorBrush Color="Black" Opacity="0"/>
                </Button.BorderBrush>
            </Button>
        </Grid>
        <TextBox x:Name="Username" TextAlignment="Center" HorizontalAlignment="Left" Height="33" Margin="16,252,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="168" FontSize="16"/>
        <TextBlock HorizontalAlignment="Left" Height="120" Margin="16,132,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="225" FontSize="20"><Run Text="Welcome to Osrs Tool!"/><LineBreak/><Run/><LineBreak/><Run Text="Please Enter your Username:"/><LineBreak/><Run/></TextBlock>
    </Grid>
</Page>

主要XAML:

<Window x:Name="GUI" x:Class="Tool.MainWindow"
        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"
        xmlns:local="clr-namespace:Tool"
        mc:Ignorable="d"
        Title="MainWindow" Height="637" Width="975.5" AllowsTransparency="True" WindowStyle="None" ResizeMode="CanResizeWithGrip">
    <Window.Background>
        <SolidColorBrush Color="White" Opacity="0.2"/>
    </Window.Background>
    <Grid MouseDown="Grid_MouseDown">
        <Frame x:Name = "Main"/>
        <Grid Opacity="0.6"/>
        <Image Margin="155,0,0,0" Source="Background.jpg" Stretch="Fill" Opacity="0.8"/>
        <Grid HorizontalAlignment="Left" Width="235" Background="White" Opacity="1
              ">
            <Button x:Name="Search" Content="&#xE71E;" HorizontalAlignment="Left" Height="33" Margin="184,252,0,0" VerticalAlignment="Top" Width="47" FontFamily="Segoe MDL2 Assets" Background="{x:Null}" Click="Search_Click" FontSize="16"/>
        </Grid>
        <Image Source="Icon.ico" Stretch="Fill" RenderTransformOrigin="0.52,0.125" HorizontalAlignment="Left" Width="229" Height="132" VerticalAlignment="Top" Margin="6,0,0,0"/>
        <Grid Margin="0,0,0,597">
            <Button x:Name="Close" Content="&#xEF2C;" Height="40" VerticalAlignment="Top" Background="{x:Null}" FontFamily="Segoe MDL2 Assets" Foreground="White" Click="Close_Click" HorizontalAlignment="Right" Width="40" Margin="0,0,1,0">
                <Button.BorderBrush>
                    <SolidColorBrush Color="#FF2C46BB" Opacity="0"/>
                </Button.BorderBrush>
            </Button>
            <Button x:Name="Maximize" Content="&#xEF2E;" Height="40" Margin="0,0,41,0" VerticalAlignment="Top" FontFamily="Segoe MDL2 Assets" Background="{x:Null}" Foreground="White" Click="Maximize_Click" HorizontalAlignment="Right" Width="40" >
                <Button.BorderBrush>
                    <SolidColorBrush Color="#FF2C46BB" Opacity="0"/>
                </Button.BorderBrush>
            </Button>
            <Button x:Name="Minimize" Content="&#xEF2D;" Margin="0,0,81,0" Background="{x:Null}" FontFamily="Segoe MDL2 Assets" Foreground="White" HorizontalAlignment="Right" Width="40" Height="40" VerticalAlignment="Top" Click="Minimize_Click">
                <Button.BorderBrush>
                    <SolidColorBrush Color="Black" Opacity="0"/>
                </Button.BorderBrush>
            </Button>
        </Grid>
        <TextBox x:Name="Username" TextAlignment="Center" HorizontalAlignment="Left" Height="33" Margin="16,252,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="168" FontSize="16"/>
        <TextBlock HorizontalAlignment="Left" Height="120" Margin="16,132,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="225" FontSize="20"><Run Text="Welcome to Osrs Tool!"/><LineBreak/><Run/><LineBreak/><Run Text="Please Enter your Username:"/><LineBreak/><Run/></TextBlock>

    </Grid>
</Window>

1 个答案:

答案 0 :(得分:0)

不安全,名称是每页和那种类型,因此它与在多个对象中使用相同名称一样安全。