
出于某種原因,visual studio不會編譯下面的代碼。
我在 .NET 6 WPF 上。
是否有任何重大更改不允許我再擴展System.Windows.Window?
我無語了。錯誤沒有意義。
我將在我的 xaml 和 cs 下面發布視窗:
<local:ExtendedWindow x:Class="Enciphered.Wpf.Window1"
x:TypeArguments="local:RoundedWindowViewModel"
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:Enciphered.Wpf"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Grid>
</Grid>
</local:ExtendedWindow>
namespace Enciphered.Wpf
{
public partial class Window1 : ExtendedWindow<RoundedWindowViewModel>
{
public Window1()
{
InitializeComponent();
}
}
}
using System.Windows;
namespace Enciphered.Wpf
{
public class ExtendedWindow<TViewModel> : Window
where TViewModel: ViewModel
{
protected TViewModel? _viewModel;
public TViewModel? ViewModel
{
get => _viewModel;
set
{
if (_viewModel is not null)
if (_viewModel.Equals(value))
return;
if (_viewModel is null && value is null)
return;
_viewModel = value;
DataContext = ViewModel;
}
}
}
}
uj5u.com熱心網友回復:
嘗試從專案 ( .csproj) 檔案中洗掉以下行,然后重新構建:
<Nullable>enable</Nullable>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/381822.html
