问题标签 [xaml]

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 回答
2928 浏览

wpf - 在 WPF ComboBox 上,是否可以为文本框和弹出窗口设置不同的前景色?

基本上我的问题源于希望文本框部分为白色,而下拉为黑色。当我将文本设置为白色时,下拉菜单显示为我想要的,但文本框中的文本本身很难阅读。将前景设置为黑色会使下拉菜单不可读。

有没有好的方法来处理这个?我还在学习WPF。

0 投票
1 回答
5660 浏览

wpf - 将 2 个 WPF 组合框数据绑定到 1 个源而不被“链接”

我有一个主从场景,其中我有 1 个 ComboBox 列出来自 ObjectDataSourceProvider 的公司。在此之下,我有 2 个 ComboBoxes 绑定到当前 Company 对象的 Contacts 属性。我需要能够在每个 ComboBox 中选择不同的联系人;但是,只要我在一个列表中更改选择,另一个列表就会更新到同一个联系人。

我尝试了不同的设置(OneWay 与 TwoWay),但到目前为止似乎没有任何效果。这是我的 XAML 的摘录。

我认为创建一个 CollectionViewSource 将是要走的路,但我无法做到这一点。有没有一种简单的方法可以使 PrimaryContact 和 AdminContact 不链接?

0 投票
2 回答
763 浏览

wpf - Is this a crazy way to handle multi Validation types with IDataError and WPF?

We are using the standard method for our controls to report broken BO rules. This is done via the interface IDataError in our BO’s and in XAML the control is bound to the BO’s property etc. This approach works OK. But we need to show 2 types of visuals in the UI depending on the type (or category if you like) of the invalidation error. If it’s a required field then we show a CueBanner (water mark) but for other types we change the colour of the controls boarder. In both scenarios we set the tool type of the error message.

The Problem with IDataError is that it doesn’t support a method/property to distinguish between error types.

The only way I can do that is by examining the error text, required field text must contain the key word “required”. The following approach doesn’t feel right but it’s the only way I can determine the type of error and then deal with it accordingly. All required field rules must have as part of the error text “required field”. To make this all work I have created a custom dependency property called ErrorMessage. In my ResourceDictionary I have a Style.Trigger for Validation.HasError. In there I set my dependency properties value to the ErrorContent. Now when my dependency properties value changes I can examine the text and set the Validation.SetErrorTemplate( myControl, newErrorTemplate) to the template to suit the error type. I have to wire up a few events to the control such as lost and got focus to manage removing or adding the cueBanner template but the whole thing will work. It’s just that I’m not sure it’s the best way to do it.

PS. When I set the ErrorTemplate i’m doing this in code, thats building and adding it. Is there a way to point Validation.SetErrorTemplate to a static resource keeping in mind that I need to switch between at least 2 types?

Your thoughts please..

0 投票
18 回答
128079 浏览

wpf - 有什么方法可以使 WPF 文本块可选?

如何允许TextBlock选择文本?

我试图通过使用样式看起来像文本块的只读文本框显示文本来使其工作,但这在我的情况下不起作用,因为文本框没有内联。换句话说,如何使它可选择?

0 投票
2 回答
3127 浏览

c# - 从没有密钥的代码创建 XAML 资源

有没有办法从代码中将资源添加到 ResourceDictionary 而不给它一个资源键?

例如,我在 XAML 中有这个资源:

我需要从代码动态创建此资源并将其添加到 TreeView ResourceDictionary。但是,在 XAML 中没有 Key 意味着它默认用于所有 FieldPropertyInfo 类型。有没有办法在没有密钥的情况下将其添加到代码中的资源中,或者有没有办法我可以使用密钥并仍然在所有 FieldPropertyInfo 类型上使用它?

到目前为止,这是我在 C# 中所做的:

显然,将资源添加到 ResourceDictionary 键为 null 不起作用。

0 投票
2 回答
17359 浏览

wpf - 如何从 ContentTemplate 绑定到周围的自定义控件?

我有以下用户控制:

这个自定义的 TabItem 定义了一个DependencyProperty“ShortLabel”来实现一个接口。我想从TabItem's中绑定到 this 和其他属性DataTemplate。但是由于奇怪的交互,其中TextBlockDataTemplate被绑定到 的父容器,该容器TabItem也称为“Self”,但在另一个 Xaml 文件中定义。

问题

为什么绑定在 TabItem.Header 中起作用,但在 TabItem.ContentTemplate 中不起作用,我应该如何继续从 DataTemplate 中获取用户控件的属性?

我已经尝试过的

  • TemplateBinding: 尝试在TabItem.
  • FindAncestor, AncestorType={x:Type TabItem}: 找不到TabItem父母。MyTabItem当我指定类型时,这也不起作用。
  • ElementName=Self: 尝试绑定到错误范围内具有该名称的控件(父容器,而不是TabItem)。我认为这给出了一个提示,为什么这不起作用:DataTemplate 不是在 XAML 中定义的位置创建的,而是显然是由父容器创建的。

我假设我可以替换整个ControlTemplate来实现我正在寻找的效果,但是由于我想保留默认外观TabItem而不必维护整体ControlTemplate,所以我非常不愿意这样做。

编辑

同时我发现问题是:如果包含s,则TabControls 不能有(任何)ItemsTemplate(包括) 。MSDN 论坛上有一个帖子解释了原因。DisplayMemberPathItemsSourceVisual

由于这似乎是 WPF 的 TabControl 的一个基本问题,所以我要结束这个问题。感谢你的帮助!

0 投票
3 回答
2519 浏览

.net - 如何在 WPF 中的上下文菜单和常规菜单之间共享菜单定义

我有一个已定义的 MenuItem,我想在一页上的两个不同菜单之间共享它。该菜单包含两个菜单之间相同的功能,我不想要它的两个副本。无论如何要在 Page.Resources 中定义一个 MenuItem 并在下面的 ContextMenu XAML 中引用它?

0 投票
4 回答
22179 浏览

c# - WPF 命令和参数

我发现 WPF 命令参数是一个限制。也许这表明我将它们用于错误的目的,但在我报废并采取不同的策略之前,我仍在尝试。

我组装了一个异步执行命令的系统,但是很难使用任何需要数据输入的东西。我知道 WPF 命令的一种常见模式是传入this. 但是this对于异步命令根本不起作用,因为所有依赖项属性都无法访问。

我最终得到这样的代码:

并且还需要 InstallServiceParametersConverter 类(加上 InstallServiceParameters)。

任何人都看到了一种明显的改进方法?

0 投票
5 回答
15060 浏览

c# - 情节提要找不到 ControlTemplate 元素

我创建了一些相当简单的 XAML,并且它运行良好(至少在 KAXML 中)。从 XAML 中调用情节提要时,情节提要运行良好,但是当我尝试从外部访问它们时,出现错误:

我正在使用流阅读器加载 XAML,如下所示:

并尝试使用以下方式运行情节提要:

我认为问题在于我正在制作动画的字段在模板中,并且情节提要正在访问按钮。

这是 XAML:

任何比我更了解 WPF 和 XAML 的人有什么建议吗?

这是错误堆栈跟踪:

0 投票
3 回答
3470 浏览

silverlight - 对 DependencyObject 和 DependencyProperty 的依赖

我正在构建一个 Silverlight 应用程序,我上次的警告之一是,如果您需要以 Silverlight/WPF 方式正确完成任何事情,您需要将您的对象建模为 DependecyObject 并使用 DependencyProperty(ies)

我发现这个模型相当麻烦,在我使用的一半类中需要静态字段和初始化程序,那么使用古老的事件驱动(观察者模式?)代替 DependencyObject 是个好主意吗?

我的目标是尽量减少代码膨胀和样板(我讨厌它们),并且真的很想知道是否有任何具有 Silverlight/WPF 经验的人有任何技巧/技术可以将 DependencyObject 和 DependencyProperty 的使用保持在最低限度?

这是一个好主意吗?