簡體   English   中英

如何在c#中打開新窗口而不會丟失xml布局

[英]How to Open New Window in c# without losing xml layout

我有一個ac #project已經在使用一個主窗口,但是當我創建了一個新窗口並使用它時

Views.Form Form = new Views.Form();
Form.ShowDialog();

頁面doe是打開的,但它沒有顯示我取消分配的xml,我認為問題出在名稱空間和derectories中,但很難解決問題,所以這是我的解決方案資源管理器

   Properities
   References
   Model
     Acteur.cs
     Tache.cs
   ViewModels
     ActeurViewModel.cs
     TacheViewModel.cs
   Views
     Form.xaml
     MainWindow.xaml
   App.xaml
   Model.edmx

這是表單窗口代碼:

.cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication2.Views
{
    /// <summary>
    /// Interaction logic for Form.xaml
    /// </summary>
    public partial class Form : Window
    {
        public Form()
        {

        }
    }
}

.xaml文件

<Window x:Class="WpfApplication2.Form"
        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:WpfApplication2"
        mc:Ignorable="d"
        Title="Form" Height="300" Width="300">
    <Grid Background="#FF142683">
        <Label  Name="Test" Content="this is a test" FontSize="43"/>
    </Grid>
</Window>

MainWindow呼叫

private void AddButtonClicked(object sender, RoutedEventArgs e)
        {
            Views.Form Form = new Views.Form();
            Form.ShowDialog();
        }

你刪除了方法“ InitializeComponent ();” 在構造函數中?

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }
}

此方法由vs自動創建,它將初始化您在XAML.cs中使用的那些控件。

由於您刪除了該方法,這就是您無法看到控件的原因。

只是嘗試創建一個新窗口,你會發現我提到的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM