Tag: xaml

如何检查XAML元素是否支持AutomationId属性

我需要一种方法来检查我的代码库中的每个WPF控件都有一个AutomationProperties.AutomationId属性。 (这是自动化UI测试所必需的。)我还需要确保将来在将来可能添加到代码库的所有表单中强制执行此要求。 我已经考虑了几种不同的方法,到目前为止,它们似乎都不是正确的方法。 选项1:为应用程序中的每个WPF表单编写unit testing。 这是一种相当简单的方法。 我已经编写了一个方法来检查DependencyControl的所有逻辑后代,并确保每个后代都有一个AutomationId。 这是一些C#: private bool AllControlsHaveAutomationId(DependencyObject control) { bool result = true; if (this.ControlHasAutomationId(control)) { foreach (object o in LogicalTreeHelper.GetChildren(control)) { FrameworkElement frameworkElement = o as FrameworkElement; if (frameworkElement != null) { result = this.AllControlsHaveAutomationId(frameworkElement); } } } else { result = false; } return result; } private bool ControlHasAutomationId(DependencyObject […]

如何将Base64字符串转换为图像,然后将其绑定到Metro风格应用程序中的GridView?

我收集了来自Web服务的产品,我在网格视图中预览了这个产品,但是我将产品的图像作为Base64字符串。 如何将其转换为图像并将其绑定到网格视图中的图像? 任何能帮助我解决这个问题的代码。

触发的内容模板

我正在尝试设置一个基于DataTrigger更改的ContentTemplate。 从语法上讲,我觉得这应该可行,但在尝试呈现页面时会导致堆栈溢出: 简单地说 工作正常 – 但我想要完成的是绑定到字段列表,但只显示必填字段。 我不能只使用Visibility = collapsed,在MyFieldDisplayTemplate中实例化所有自定义控件会产生巨大的开销。 我的目标是让非必需字段在ItemsControl中具有完全不同(空)的控件模板。 有关如何设置此触发器的任何想法?

TextBlock文本不在DataGridCell中垂直居中

我在C#中创建一个DataGrid (来自代码隐藏/不是XAML),但无论我尝试什么,我都无法使文本在数据单元格中垂直居中: 我开始时: var CellStyle = new Style(typeof(DataGridCell)) { Setters = { new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center) } }; 哪个正确地定位单元格并使文本水平居中(根据上面的屏幕截图)。 尝试垂直居中文本,我知道TextBlock不支持垂直内容对齐,只支持父元素中自己的垂直对齐。 根据这个问题( WPF TextBlock中的文本垂直对齐 )我试图使用Padding伪造它: var CellStyle = new Style(typeof(DataGridCell)) { Setters = { new Setter(TextBlock.PaddingProperty, new Thickness(5)), new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center) } }; 这没有任何区别。 然后我尝试了这个: var CellStyle = new Style(typeof(DataGridCell)) { Setters = { new Setter(DataGridCell.VerticalContentAlignmentProperty, VerticalAlignment.Center), […]

uwp:如何根据listview项的值更改listview项的背景颜色?

编辑:UWP App与WPF应用程序不是100%相同。 我有一个带有ListView的uwp应用程序。 在ListView中,我使用带有测试类的DataTemplate。 它显示测试和点的名称。 我想要完成的是一个触发器! 检查点是否大于ie:50然后将ListViewItem 的背景颜色更改为红色。

如何将方形图像蒙版成圆角图像?

因为我想在我的Image控件中实现圆角面罩我设计了这样的控件 但是我正在接受控制 。 有人有想法用边框颜色填补角落吗?

如何从ListViewItem的DataTemplate中的TextBox获取文本

我不知道如何在按钮点击后从“firstBox”和“secondBox”获取文本。 我只得到了这个对象 private void Button_Click_1(object sender, RoutedEventArgs e) { var myobject = (sender as Button).DataContext; }

在双击时,XAML中是否有一种方法可以选择文本框中的所有文本?

有没有办法纯粹通过XAML突出显示文本框中的所有文本,或者是否必须在Xaml.cs中完成 谢谢!

如何在Windows 8 metro应用程序中拥有用户提示对话框?

我想从模态窗口获取我的应用程序的一些用户输入,如Name,DOB等 为此我需要显示一个对话框,其中包含文本框和其他控件。 通常在WinForms / WPF中我会创建一个inheritance自Form / Window类的类,并使用Show / ShowDialog方法将表单呈现给用户 如何在使用XAML / C#的Windows 8 metro应用程序中实现此行为? 我查看了Windows.UI.Popups命名空间下的MessageDialog类 但它只显示像经典MessageBox的消息。 我查看了另一个CoreWindowFlyout类,也不确定是否可以将其用于我期望的行为。

如何更新StackPanel的布局?

问题是,如果您单击按钮并展开电话号码,堆栈面板和边框会展开,这很好,但如果您折叠它,堆栈面板和边框不会折叠。 使用以下代码隐藏: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); myListBox.ItemsSource = new List() { 1, 2 }; //add 2 elements; } private […]