在初始化窗口视图之后,programm生成数百万个绑定实例

时间:2017-03-25 16:14:57

标签: c# wpf mvvm

我使用文本模板编程应用程序。

我使用Visual Studio 2017. .NET Framework 4.6.2。 WPF和MVVM模式。

因此,当我为View创建实例时,programm会生成许多带有绑定或其他内容的实例。

我的创建和显示视图的命令代码:

public RelayCommand AddTemplate => addTemplate ??
(addTemplate = new RelayCommand(obj =>{
TemplateAddOrEditView templateAddView = new TemplateAddOrEditView(){
Owner = Application.Current.MainWindow};
TemplateAddOrEditViewModel templateAddViewModel = new
TemplateAddOrEditViewModel(SelectedGroup, templateAddView);
templateAddView.DataContext = templateAddViewModel;
templateAddView.Show();}));

XAML中的按钮代码

<Button Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Content="Новый шаблон" Margin="3,0,3,3" FontSize="14" Background="White" BorderBrush="Black" Command="{Binding AddTemplate}"></Button>

Before i press button

After of pressing button

0 个答案:

没有答案
相关问题