使用函数调用.xaml文件时wpf不显示内容

huwehgph  于 2022-11-18  发布在  其他
关注(0)|答案(3)|浏览(202)

当我使用函数运行Main_win.xaml时,wpf页面不显示任何内容App.xaml:

<Application x:Class="test.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:salesandwarehousingsystem"
         ShutdownMode="OnExplicitShutdown" 
         Startup  = "Application_Startup" >
</Application>

App.xaml.cs:

private void Application_Startup(object sender, StartupEventArgs e)
    {
        Main_win main_Win = new Main_win();
        main_Win.ShowDialog();}

主要_win.xaml:

<Window x:Class="test.window.Main_win"
    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:salesandwarehousingsystem.window"
    xmlns:custom="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" 
    mc:Ignorable="d"
    Title="Main_win" Height="660" Width="1300">
<Grid>
    
    <Ribbon >
        <Ribbon.QuickAccessToolBar>
            <RibbonQuickAccessToolBar >
                <RibbonSplitButton  >
                    <RibbonSplitMenuItem Header=" About Us"/>
                    <RibbonSplitMenuItem Header=" Contact Us"/>
                    <RibbonSplitMenuItem Header=" Exit"/>
                </RibbonSplitButton>
            </RibbonQuickAccessToolBar>
        </Ribbon.QuickAccessToolBar>
        <Button Content="Button" Height="21" Width="136"/>
    </Ribbon>
    <Button Content="Button" Margin="561,282,422,282"/>

</Grid>

结果:

无论您添加什么...按钮或任何对象...结果都一样

wlzqhblo

wlzqhblo1#

我运行了你给我看的代码。
它显示了一个填充的窗口,尽管有绑定错误。

对于已修复的错误,请从RibbonWindow继承Main_win。
第一个

brccelvz

brccelvz2#

Win_Login.xaml.cs

public partial class Win_login : RibbonWindow
    {
        public Win_login(object @object)
            :this() // Calling the default constructor so that there is no code duplication.
        {

        }

        public Win_login()
        {
            // XAML processing is performed by this method.
            // Therefore, it is necessary to ensure its call in any constructor.
            InitializeComponent();
        }
p8ekf7hl

p8ekf7hl3#

@EldHasp谢谢你的帮助。Main_win页面的问题解决了。但是我有另一个页面有这个问题
Win_Login.xaml.cs文件系统:

public partial class Win_login : RibbonWindow 
{
    public Win_login(object @object)
    {
        InitializeComponent();
    }

    public Win_login()
    {
    }
      
    private void btn_login_Click(object sender, RoutedEventArgs e)
    {
      
        if (txt_username.Text == "a" && txt_password.Password == "123")
        {
            Main_win Mainwindow = new Main_win();
            
        }
        else
        {
            MessageBox.Show("user not found");
        }
    }

    private void btn_Exit_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }
}

}
xaml文件名:

<RibbonWindow  x:Class="salesandwarehousingsystem.Win_login"
    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:salesandwarehousingsystem"
    mc:Ignorable="d"
    Title="Win_login" Height="400" Width="600" Background="Transparent" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen" >
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Rectangle Stroke="Black" Margin="20,10,0,10" RadiusX=" 15" RadiusY=" 15">
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF134116"/>
                <GradientStop Color="#FF68E370" Offset="1"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <Rectangle Stroke="Black" Margin="20,10,0,290" RadiusX=" 15" RadiusY=" 15">
        <Rectangle.Effect>
            <DropShadowEffect/>
        </Rectangle.Effect>
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF0F510E" Offset="1"/>
                <GradientStop Color="#FF1FAE1E" Offset="0"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <Label Content="test" HorizontalAlignment="Center" Height="41" Margin="0,19,0,0" VerticalAlignment="Top" Width="491" FontFamily="Segoe Script" FontSize="28" Foreground="#FF0C1462"/>
    <Label Content="Login Form" HorizontalAlignment="Left" Margin="54,65,0,0" VerticalAlignment="Top" Height="45" Width="156" FontSize="24" FontFamily="Segoe Script" Foreground="#FF0C1462"/>
    <Label Content="USER NAME:" HorizontalAlignment="Left" Margin="30,150,0,0" VerticalAlignment="Top" Height="34" Width="91" FontFamily="Arial Black"/>
    <Label Content="PASSWORD :" HorizontalAlignment="Left" Margin="30,200,0,0" VerticalAlignment="Top" Height="39" Width="91" FontFamily="Arial Black"/>
    <TextBox x:Name="txt_username" HorizontalAlignment="Left" Margin="150,154,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" Height="26" FontFamily="Arial Narrow" Foreground="White">
        <TextBox.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FFB3B0E8" Offset="1"/>
            </LinearGradientBrush>
        </TextBox.Background>
    </TextBox>
    <Button x:Name="btn_login" Content="LOGIN" HorizontalAlignment="Left" Margin="30,299,0,0" VerticalAlignment="Top" Height="37" Width="91" Foreground="White" Click="btn_login_Click" >
        <Button.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF8F614F" Offset="0.993"/>
                <GradientStop Color="#FF3F1010"/>
                <GradientStop Color="#FF614542" Offset="0.347"/>
            </LinearGradientBrush>
        </Button.Background>
    </Button>
    <Button x:Name="btn_Exit" Content="EXIT" HorizontalAlignment="Left" Margin="150,299,0,0" VerticalAlignment="Top" Height="37" Width="91" Foreground="White" Click="btn_Exit_Click">
        <Button.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF8F614F" Offset="0.993"/>
                <GradientStop Color="#FF3F1010"/>
                <GradientStop Color="#FF614542" Offset="0.347"/>
            </LinearGradientBrush>
        </Button.Background>
    </Button>
    <PasswordBox x:Name="txt_password" HorizontalAlignment="Left" Margin="150,200,0,0" VerticalAlignment="Top" Width="120" Height="29" FontFamily="Arial Narrow" Foreground="White">
        <PasswordBox.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FFB3B0E8" Offset="1"/>
            </LinearGradientBrush>
        </PasswordBox.Background>
    </PasswordBox>
</Grid>

现在这个页面没有任何装订问题...

相关问题