问题标签 [visual-tree]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
12113 浏览

wpf - WPF - 如何检测何时添加了新的 Visual 子元素?

基于一些自定义安全设置,我将窗口子控件更改为只读和禁用。为此,我在窗口加载时循环遍历子控件。

这工作得很好。99% 完美。

在我的窗口中,我有一个 ItemsControl,其内容基于 ComboBox。更改 ComboBox,ItemsControl 中的子控件再次数据绑定。但是,安全性(只读/禁用)不再是真的。

在你跳到解决方案之前,我知道我可以处理 ComboBox changed 事件;但是,我有很多这样的盒子,并且无论我的开发人员向窗口/表单添加什么内容,我都没有一个可以在窗口级别应用的通用解决方案(想想:基础)。

我的问题(很抱歉,长时间的引导)是,我如何检测由于某些动态活动(如数据绑定)而将新孩子添加到窗口的时间?是否有 NewChildAdded 事件?是否有 DataBindingJustChangedThings 事件?

一定有什么事。

如果您的解决方案包含计时器,则无需回复。我的表单太复杂了,无法处理额外的负载 - 滴答之间的延迟实在是一个安全问题。

您可能在想,只需将外部容器设置为只读或禁用即可。但这会对扩展器、多行文本框和列表框等内容产生负面影响。这种方法不够细化。当然,这是我们之前开始迭代的地方。

如果您的解决方案包含样式,则需要包括我如何在每个控件的基础上覆盖您的方法。某些控件(如复选框)无法禁用,因为它们在 UI 布局中有用途。

很抱歉有限制,但我计划在生产中使用该解决方案。

谢谢你。

0 投票
2 回答
2015 浏览

c# - 将控件设置为最上面的 silverlight

[情况]

我有一个自定义项目控件,我将其添加到堆栈面板,之后可以通过拖动自由移动。

[问题]

添加 3 个项目后,我将第一个项目拖到第二个或第三个项目上,它跳到它后面。

当我将第二个项目拖到第一个项目上时,它在前面,但是当我将它拖到第三个项目上时,它在它后面。

我怎样才能使控件拖动始终位于可视化树的顶部?

0 投票
3 回答
1009 浏览

c# - 当它们都在 DataGridTemplateColumn 中时,从 Button 中清除 TextBlock

我有一个带有 DataGridTemplateColumn 的 DataGrid。DataGridTemplateColumn 包含一个按钮和 TextBlock。我希望按下按钮将清除 textBlock 的文本。我怎么做 ?

在此处输入图像描述

XAML:

CS代码:

0 投票
1 回答
1098 浏览

wpf - WPF 3.5 嵌套数据网格行详细信息未显示在可视树中

所以我构建了一个漂亮的嵌套数据网格,看起来像这样:

由于 RowDetailsVisibilityMode 属性设置为 VisibleWhenSelected 时,行的节点 DataGridDetailsPresenter 有 0 个子节点。当属性设置为可见时,我可以看到 DataGridDetailsPresenter 子级。

当 RowDetailsVisibilityMode 属性为 VisibleWhenSelected 时,如何强制包含可视树中的所有节点?

非常感谢任何输入。

0 投票
1 回答
477 浏览

wpf - 如何测试silverlight中视觉树渲染的速度?

例如,我创建了一个包含大量形状的 Canvas,如下所示:

然后我将所有画布添加到主页:

这两行代码运行所需的时间并不多,但是所有形状都需要一段时间才能显示在屏幕上,并且 UI 会在一段时间内无响应。

在 WPF 中,我可以通过执行以下操作来测试可视化树的渲染时间:

这样,秒表在创建逻辑树后启动,并在渲染(加载)可视化树后停止。

但是在silverlight中,没有DispatcherPriority,那我该怎么做类似的事情呢?

谢谢

0 投票
0 回答
307 浏览

silverlight - 通过从可视树中删除来清除根数据上下文时,在树的下方绑定仍然存在

[Silverlight] 我有一个大型的可视对象树,我要从可视树 (Grid.Children.Clear()) 中删除,在删除根的 DataContext 时将其清空,但在树的下方,一个看起来像这样的绑定

与之前绑定的对象保持绑定。有人会认为,一旦它的 DataContext 被清空,绑定就会清除。像这样清除网格的孩子是错误的吗?还有什么可能导致它?

0 投票
1 回答
138 浏览

silverlight - Replace a control within a user control through dependency property

I've made a simple project to illustrate my problem. I have a user control ('ButtonPod') that houses a button and a rectangle:

#xA;

I want to use this user control throughout my application, but I need to change the Button in the middle. I need control over all the properties of the Button, so I don't want to just expose DependencyProperties like 'ButtonText' or 'ButtonSize' - I would rather define the entire Button whenever I use the control. So I set up a dependency property ('CenterButton') like this:

#xA;

Then I try defining the 'CenterButton' on my MainPage.xaml, within my user control:

#xA;

But when I load up the app, all I see is a button that says "Old button content" -- why isn't my button being replaced? Stepping through, I can see that the DependencyProperty gets hit and the 'ButtonOnPage' property gets set, but the visual tree does not update. Any ideas?

0 投票
1 回答
536 浏览

c# - How do I use parent's ItemsHost for HierarchicalDataTemplate in XAML?

I have a tree- or menu-like data structure which I want to display in a Panel (specifically a self-made PolarPanel), but all items must be VisualChildren of the same panel.

If I define a HierarchicalDataTemplate, I need to create an ItemsControls and specify it as IsItemsHost, or am I mistaken here? Can I somehow reference the parent's ItemsHost?

(My first workaround was to have a GetAllTheChildren property in the root node which returns all children and all children of the SelectedChild, recursively. This doesn't easily work together with ObservableCollection, because changes have to bubble up to the root to refresh GetAllTheChildren again (which reloads more items than would be neccessary).)

I know I can do it in code-behind by creating and drawing the items' Views into the same parent, but I'm searching for a nice WPF, indirect, automagic way.

EDIT: I am now using an improved workaround, where all ItemControls / Panels are drawn on top of each other. This preserves the hierarchical aspect, which makes this a much better solution than the one mentioned above (with GetAllTheChildren). But it still doesn't answer my question...

This is what it looks like graphically:
PolarMenu example
Note how the hierarchical elements have to be arranged in the same space.

Is there a clean and simple solution to this?

0 投票
1 回答
681 浏览

silverlight - 我可以从 VisualTree 中删除 ChildWindow 并将其放回以实现全屏吗?

我有一个弹出窗口,它是一个 ChildWindow。在该弹出窗口中,我有一个 UserControl (MediaPreviewView),它有一个 MediaElement 和一些用于控制视频的按钮。我的要求是我需要一个全屏按钮,并在用户单击该按钮时全屏显示视频。

我正在使用 MVVM,所以我决定尝试使用 MVVM Light 中的消息传递。我正在向我的基本视图发送一条消息。在该视图的代码隐藏中,我显示了一个网格(隐藏在 XAML 的底部,具有高 zindex)。我的消息包含 MediaPreviewControl 并且我正在将 Grid.Children.Add( 设置为控件。我尝试了多种方法,并且可以使 ChildWindow 不可见,但按钮不起作用。似乎 ChildWindow仍然在按钮的顶部,即使宽度和高度为 0。是否有更好的使我的 MediaPreviewView 全屏显示的可行方法?

0 投票
2 回答
428 浏览

silverlight - 为什么我每页只能有一个 Silverlight UserControl 实例?

它很蹩脚,但我尝试UserControl在我的 SilverlightPage中添加两个,我得到一个异常,告诉我(通过大量挖掘)相同的控件名称已用于视觉树两次。所以我里面的控件被命名了UserControl,所以我一次只能包含其中一个。这是真的,还是我没有意识到什么?微软真的放弃了代码重用吗?这很蹩脚。UserControlPage

编辑

对于来这里的人,我得到了 System.Resources.MissingManifestResourceException 异常。花了一些时间才发现问题出在可视化树中的模糊名称。希望这对您有所帮助。以下是完整的异常文本。

进一步编辑

这是我的 XAML:

这是我的用户控件的 XAML: