如何跨 Silverlight 应用程序覆盖 TextBlock IsHitTestVisible
我会保存我为什么他们这样做的方式在其他地方咆哮,所以...
我试图阻止 TextBlocks 在我的 Silverlight 应用程序中获得焦点。似乎在我的应用程序的基页面类(页面继承)中的任何 TextBlock 上添加此属性的设置器都有意义,但是 1)我可能是错的,2)我似乎不太正确。
我尝试过添加如下代码的变体:
this.Style.Setters.Add(new Setter(TextBlock.IsHitTestVisibleProperty, false));
添加到我的应用程序基 Page 类(直接从 Page 继承)的构造函数中或添加到页面 Loaded 事件处理程序中。但该主题的大多数变体似乎都不起作用(通常看起来好像所有正确的成员还不存在或 XamlParseExceptions。
它可能非常简单,但显然我的大脑也是如此。有什么想法吗?
I'll save my why did they do it this way rants for elsewhere, so...
I'm trying to prevent TextBlocks from getting focus across my Silverlight app. It seems like adding a setter for this property on any TextBlock within my application's base page class (Page-inheriting) makes some sense, but 1) I'm probably wrong and 2) I can't seem to quite get it right.
I've tried variations on adding code like this:
this.Style.Setters.Add(new Setter(TextBlock.IsHitTestVisibleProperty, false));
to the constructor of my app's base Page class (inherits directly from Page) or in a page Loaded event handler. But most variations on that theme don't seem to work (generally seeming as though all the right members don't yet exist or XamlParseExceptions.
It's probably absurdly simple, but so is my brain, apparently. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以只使用隐式样式
通常,如果在单独的资源字典中,样式会合并在 App.xaml 文件的顶层,或者您可以简单地在其中添加样式。我自己对 Silverlight 还很陌生,所以我只是报告我所看到的。
假设您一开始有一个空的 App.xaml,它可能看起来像这样:
这测试起来非常简单,您可以添加一个前景色设置器并查看是否所有 TextBlock 都采用该样式。
You could just use an implicit style
Generally, styles are merged at the top level of the App.xaml file if in separate resource dictionaries or you could simply add your style there. I'm pretty new to Silverlight myself, so I'm only reporting what I've seen.
Assuming you have an empty App.xaml starting out, it may look something like this:
This is pretty simple to test, you could add a Foreground color setter and see if all of your TextBlocks pick up the style.