使用runtime动态添加BOOL属性为什么报错

runtime添加属性是添加的对象而不是本身的类型。

我们来看一看这个方法的参数:

第三那个参数 id  _Nullable value 苹果给出的定义 :

//@param value The value to associate with the key key for object. Pass nil to clear an existing association.  ------对与对象的键相关联的值进行赋值。通过NIL来清除现有的关联。


BOOL是一个本征型,所以在此处使用BOOL类型出此错误;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果WindowStyle属性设置为None没有隐藏窗口的边框和标题栏,可能是因为应用程序的框架不允许窗口样式被覆盖。在这种情况下,可以尝试使用以下方法: 1. 在App.xaml文件中添加以下样式: ```xaml <Style TargetType="Window"> <Setter Property="WindowStyle" Value="None"/> <Setter Property="AllowsTransparency" Value="True"/> <Setter Property="Background" Value="Transparent"/> </Style> ``` 这个样式将应用于所有的窗口,它将WindowStyle属性设置为None,AllowsTransparency属性设置为True,以及Background属性设置为Transparent。这将导致窗口被渲染为透明的,从而隐藏窗口的边框和标题栏。 2. 在Window的Loaded事件处理程序中使用Win32 API来隐藏窗口的边框和标题栏。示例代码如下: ```c# using System.Runtime.InteropServices; using System.Windows; namespace WpfApp1 { public partial class MainWindow : Window { [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); [DllImport("user32.dll")] private static extern int GetWindowLong(IntPtr hWnd, int nIndex); [DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); private const int GWL_STYLE = -16; private const int WS_SYSMENU = 0x80000; private const int WS_MINIMIZEBOX = 0x20000; private const int WS_MAXIMIZEBOX = 0x10000; private const int WS_THICKFRAME = 0x40000; private const uint SWP_NOSIZE = 0x0001; private const uint SWP_NOMOVE = 0x0002; private const uint SWP_NOACTIVATE = 0x0010; private readonly IntPtr HWND_TOPMOST = new IntPtr(-1); public MainWindow() { InitializeComponent(); Loaded += MainWindow_Loaded; } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Hide the window border and title bar IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle; int style = GetWindowLong(hwnd, GWL_STYLE); SetWindowLong(hwnd, GWL_STYLE, style & ~(WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME)); // Set the window position to cover the entire screen SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); } } } ``` 这个方法使用SetWindowLong函数来移除窗口的菜单、最小化和最大化按钮、改变窗口大小的边框等,并使用SetWindowPos函数将窗口移动到整个屏幕的位置。这将导致窗口的边框和标题栏被隐藏。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值