It's a strange demand. If you have a closing button,why you disable it's func. But you can realize it with mvvm like this:
add two ref:
- Microsoft.Expression.Interactions.dll
- System.Windows.Interactivity.dll
add two xmlns:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
create trigger to window:
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:control="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
Title="MainWindow" Height="350" Width="525">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<ei:CallMethodAction TargetObject="{Binding}" MethodName="WindowsClosing"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid >
</Grid>
</Window>
edit viewmodel,and creat closing func:
public void WindowsClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}