Home > Blockchain >  wpf not showing content when i call the .xaml file using a function
wpf not showing content when i call the .xaml file using a function

Time:10-17

when i run Main_win.xaml using a function, wpf page not showing any content 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();}

Main_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>

and result:

main_win.xaml

no matter what you add... button or any object...same result

CodePudding user response:

I ran the code you showed.
It displayed a populated window, albeit with binding errors.
enter image description here

For errors fixed, inherit Main_win from RibbonWindow.

<RibbonWindow x:Class="test.window.Main_win"
    public partial class Main_win : RibbonWindow

enter image description here

CodePudding user response:

@EldHasp thanks for your help. problem with Main_win page solved. but i have another page with this problem

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();
    }
}

}

win_login.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>

and now this page don't have any binding issues...

CodePudding user response:

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();
        }
  • Related