gpt4 book ai didi

WPF 通用窗口

转载 作者:行者123 更新时间:2023-12-04 06:29:41 25 4
gpt4 key购买 nike

我想做一个可重用的 WPF 窗口 适用于不同类型的T。
我有一个设计器和一个代码隐藏文件。

我可以做这样的事情吗?

/*  Code behind file */
public partial class MyWindows<T> : Window
{}

最佳答案

无耻抄袭here (因此未经测试)

public class ViewBase<T> : Window, IView where T : class, IViewModel 
{
public virtual T Model
{
get { return DataContext as T; }
set { DataContext = value; }
}
}

和 XAML
<src:ViewBase 
x:Class="View"
x:TypeArguments="src:IViewModel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:MyNamespace"
Height="480" Width="640">
...
</src:ViewBase>

关于WPF 通用窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1321914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com