问题标签 [contentpresenter]
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.
wpf - ViewModel 更改时淡出/淡入
我的 WPF 应用程序的主窗口有一个标题栏/导航区域,该区域在应用程序的整个生命周期内都存在,然后是大多数用户交互发生的工作区。(它都是按照 MVVM 模式的精神编写的,我可能对代码隐藏有过分的反感:/)这个工作区只是 a ContentPresenter
,它的内容绑定到 aMainWindowViewModel
的 type 属性ISomeArbitraryVMInterface
。在我的代码中,这个属性是通过DomainEvent
从任何地方提出来更新的。
说了这么多,当DomainEvent
被触发并且内容ContentPresenter
被改变时,我想ContentPresenter
通过动画改变它的不透明度——从用户的角度来看,我希望它看起来好像当前视图淡出,使用 new进行ContentPresenter
更新ISomeArbitraryVMInterface
,然后对应于 new 的新 ViewISomeArbitraryVMInterface
淡入。
我的第一个想法是每当 Content 属性发生变化时让 ViewModel 触发一个事件,然后我意识到我已经完成了我的DomainEvent
实现,但是我想不出一种方法让 View “监听”事件然后同步淡出/更新/淡入。任何解决此类问题的见解将不胜感激。如果有一个优雅的解决方案,我会为后代发布一些代码片段。
wpf - 如何为 Wpf DataGrid 使用模板?
我有一个这样的数据网格模板:
并像这样使用它:
我想在模板内的 ScrollViewer 中显示数据网格,但它没有显示任何内容。有什么问题?
wpf - 包含带有内容的 UserControl
我创建了一个用户控件。我想将其包含在此代码中:
那是用户控件:
现在我的问题:
如果我将它与以下代码集成,
我收到的结果是:
那不是我想要的。
但是当我将它与这段代码集成时,我得到了想要的结果。
我的第一种方式有什么问题?
wpf - WPF ItemsControl -> ContentPresenter
我希望有人可以帮助我解决我的ItemsControl
问题:)
我使用 aItemsControl
作为Grid
在MVVM(以及单元格内容)ItemsPanel
中添加/删除的一个,Column/RowDefinitions
这工作正常,但是当我尝试添加一个GridSplitter
拆分器时,显示但他不工作。原因是为每个项目ItemsControl
添加一个新的......ContentPresenter
当children 属性中的项目是 typeof时,有什么方法可以用ContentPresenter
ControlGridSplitter
替换?Type
SplitterVM
我也在尝试将Splitters
on绑定Grid
为 anDependencyProperty
但是当我使用ItemsPanel
它时它不起作用,因为我无法添加Children
到Panel
...
这是我的代码:
wpf - XAML 将属性绑定到 ContentPresenter 中的 UserControl
我有名为 EditorView 的 UserControl,它根据其内容显示不同的“编辑器”(其他用户控件)。
这是 EditorView 只是为了测试我用 TextBlock 替换 FontEditor 的绑定:
根据 EditorView.Content 选择正确的模板,在 TextBlock 的情况下,绑定按需要工作,但在 TextureEditor 的情况下,TextureName 属性不是。
这是 TextureEditor 的片段:
自从我使用 UserControl 以来,我有什么特别需要做的吗?也许不同的命名空间是问题所在?
wpf - 如何为 ComboBox 内容演示者使用内容模板?
在下面的文件中,有一个用于 COmboBox 的示例 - 控件模板。 http://msdn.microsoft.com/en-us/library/ms752094(v=vs.85).aspx
我尝试使用以下 XAML 为内容演示者添加内容模板。但它将值“1”显示为“[1,1]”。
如何将 selectedValue 绑定到 textblock 的文本?
c# - WPF - Unable to bind properties of control in ContentPresenter to parent control
I have a custom control that is used in a form, this control combines a label and a textbox. When the form is in read only mode the control is changed to show a label instead of the textbox. To do this, I have defined a Content Template for my control, as follows:
ReadOnlyContentPresenter
's content is a label that's been applied the following style:
This works fine for about 80 controls, but when I add more controls to the form then the binding in the label style fails to find the source (error 4):
The same happens with the style applied to the editable part of the control. I think the issue is related to the amount of controls being processed, if I move the code of control no. 81 (failing) right above control no. 80 (working), the binding in control no. 81 works now, but the one in control no. 80 fails. I did this for several controls, and the behaviour is consistent.
I'm still not clear as to how the AdornerDecorator
works exactly, and while investigating I found this question that mentions a problem with having more than 144 adorners in an adornerlayer, so I removed the AdornerDecorator
's in my code only to find that the binding issue that was happening to controls no. 81 and over is now happening to all my FormFieldControl
's.
Finally, I decided to try with ContentControl
's instead of ContentPresenter
's in my control template. This works fine for all the controls in the form. I know that ContentPresenter
is a lightweight form of ContentControl
and that it's more suitable to use inside a content template than theContentControl
is. However, I don't quite understand why the bindings fail when using a ContentPresenter
and work when using a ContentControl
.
I also find it odd that only a limited set of controls work, and when not using the AdornerDecorator none of them will find the binding source.
Has anyone come across something similar? Is there something I'm doing wrong with the ContentPresenter
? Or if this is expected behaviour, could someone help me understand what's going on?
Any ideas are appreciated.
c# - 扩展 Window 类的 ContentPresenter 在设计时不显示内容
我目前正在编写一个扩展 Window 的 Dialog 类(无外观控件),并使用 XAML 样式为该类分配一个默认 ControlTemplate。
我希望我的对话框模板的“按钮”部分是可替换的,但如果没有指定其他内容,则使用一组默认按钮预先填充它。这就是为什么我添加了一个名为我的类的依赖属性。ButtonContent
(请参阅下面的DefaultButtons
XAML)在我运行应用程序时正确呈现,但Visual Studio 2010 的设计预览不会呈现内容。为什么这没有发生?
我的对话框类如下所示:
这是我的 XAML:
当我启动应用程序时,它看起来像这样:
VS2010 设计器渲染了这个:
编辑:如评论中所述,将上述样式放在 Themes\Generic.xaml 而不是我从 App.xaml 中包含的资源字典中不会改变任何内容。
编辑 2:如果我像这样显式覆盖默认值ButtonContent
,设计器也不会显示任何内容。在运行时,一切正常:
编辑 3:如果我将ButtonContent
属性添加到 aUserControl
而不是我的Dialog
类 extends Window
,ButtonContent
则在用户控件中正确显示...此外,VS2010 似乎将上面定义的样式应用于任何窗口,而不仅仅是 class 的那些Dialog
,尽管我已经适当地设置了 TargetType ......很奇怪!
wpf - 将 ContentPresenter.Content 绑定到 TemplatedParent (WPF/Silverlight)
基本上,我想覆盖,例如:TextBlock
over Button
,通过使用ControlTemplate
(应用于 this Button
),但我不想摆脱它的默认模板。
例子:
它Button
去掉了它的默认模板:
相反,我想收到这样的东西:
可以通过使用ControlTemplate
吗?我试图绑定TemplatedParent
到 ContentPresenter.Content
这里:
或其他组合,但我无法使其工作。
编辑:
因为我希望不仅可以将其应用于TextBlock
按钮(这只是一个示例),而且可以应用于Control
任何Control
. 另外,我不想创建UserControl
,因为我想尽可能保持 xaml 干净(我的意思是使用系统控件) - 并且只是TextBlock
通过使用ControlTemplate
.
.net - 如何设置触发器内的 TabItem ContentPresenter 的样式?
我正在重新设置 TabItem 的样式,并希望 TabItem Header 的背景、前景和文本颜色根据是否选择而有所不同。我可以在 ControlTemplate.Triggers 之外成功更改 ContentPresenter 的 TextBlock,但我不确定如何从 Trigger 中“获取”它。
这是我的 XAML: