c# - 如何在 C# 中打开新窗口而不丢失 xml 布局
问题描述
我有一个 ac# 项目已经在一个主窗口工作,但是当我创建一个新窗口并使用
Views.Form Form = new Views.Form();
Form.ShowDialog();
该页面已打开,但未显示我设计的 xml,我认为问题出在名称空间和目录中,但很难解决问题,所以这是我的解决方案资源管理器
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 中使用的那些控件。
由于您已删除该方法,这就是您看不到控件的原因。
只需尝试创建一个新窗口,您就会找到我提到的方法。
推荐阅读
- c# - 对列表中的项目进行排序
- database - 支持原始 SQL 的开源数据库迁移工具
- html - 使用 flexbox 时引导文本不会截断
- r - 可以使用“sprintf”功能更改列的格式吗?
- php - PayPal API 购物车和 Webhooks?
- r - 访问通过模块创建的数据框及其名称并将它们存储在列表中
- r - 我在 R 中的 performanceAnalytics 包中的 performanceSummary 图表有问题
- javascript - 如何通过模拟选择器和/或 redux store 来编写 Redux Saga 测试
- docker - 当有多个摘要的标签时,docker pull 如何工作(用于 os/arch)
- java - 从 python 服务器发送到 java 客户端的定时数据