Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在自定义FrameworkElement上设置指针事件样式_C#_Wpf_Uwp_Uno Platform - Fatal编程技术网

C# 如何在自定义FrameworkElement上设置指针事件样式

C# 如何在自定义FrameworkElement上设置指针事件样式,c#,wpf,uwp,uno-platform,C#,Wpf,Uwp,Uno Platform,我正在尝试在用Uno构建的WebAssembly应用程序中创建一个文件对话框。我在页面中添加了一个自定义框架元素来创建,如下所示: [HtmlElementAttribute("input")] public sealed partial class PicInputControl : FrameworkElement { public PicInputControl() { this.SetHtmlAttribute("type&quo

我正在尝试在用Uno构建的WebAssembly应用程序中创建一个文件对话框。我在页面中添加了一个自定义框架元素来创建
,如下所示:

[HtmlElementAttribute("input")]
public sealed partial class PicInputControl : FrameworkElement
{
    public PicInputControl()
    {
      this.SetHtmlAttribute("type", "file");
      this.SetHtmlAttribute("accept", "image/png, image/jpg, image/bmp, image/jpeg");
      this.ClearCssStyle("pointer-events");
    }
}
当应用程序运行时,css样式选项
指针事件
默认设置为
none
,即使在清除
指针事件
样式时也是如此。这需要是
auto
,以便能够通过鼠标单击与ui元素交互


如何在此控件上设置指针事件?

CSS样式在运行时基于命中测试的WinUI规则,因此从ctor更改它不会产生任何效果

要将其设置为
auto
,您需要确保自定义元素符合“点击可见”的条件。一个简单的方法是设置一个非空的
Background

[HtmlElementAttribute(“输入”)]
公共密封部分类PicInputControl:FrameworkElement
{
公共PicInputControl()
{
此.SetHtmlAttribute(“类型”、“文件”);
这个.SetHtmlAttribute(“接受”,“图像/png,图像/jpg,图像/bmp,图像/jpeg”);
这个.ClearCssStyle(“指针事件”);
背景=SolidColorBrushHelper。透明;
}
}

这完美地解决了我的问题。非常感谢你!你有没有完全实现过?我现在正试着这么做,但不知道以后该怎么办。