Tag: xaml

访问flipview中第i项内的xaml控件

我有一个由一些代码填充的flipview(我不明白如何修改应用程序)。 从名为“FeedUrl”的文本块我想提取存储在其中的URL。 使用url解析该url指向的html页面 处理完后在richtextblock中显示一些名为“content”的内容。 我面临的唯一问题是如何在flipview的每个项目中引用textblock和richtextblock。 为了获得参考项目,我尝试了两种解决方案: 我已经尝试过这段代码了 var myTextBlock= _Children.OfType().FirstOrDefault(c => c.Name.Equals(“test”)); 特别 .OfType()给出错误 ‘System.Collections.Generic.List’ does not contain a definition for ‘OfType’ and no extension method ‘OfType’ accepting a first argument of type ‘System.Collections.Generic.List’ could be found (are you missing a using directive or an assembly reference?) 我也试过这里给出的另一个解决方案,但我总是得到一个空引用。 我也收到警告线 var item = itemsControl.ItemContainerGenerator.ContainerFromItem(o); Windows.UI.Xaml.Controls.ItemContainerGenerator.ContainerFromItem(o); is […]

C#WPF – DragMove并单击

我需要一个控件来调用MouseLeftButton上的Window的DragMove(),但是在单击时仍然可以运行。 如果调用DragMove(),则不会触发Click和MouseLeftButtonUp,因为DragMove()是一个阻塞调用,直到它们释放鼠标按钮。 有没有人知道一个解决方法来使这项工作? 我已经尝试过基于Thread.Sleep的这个hack,它允许点击工作,如果它快于100毫秒,但它对用户不起作用: ThreadPool.QueueUserWorkItem(_ => { Thread.Sleep(100); Dispatcher.BeginInvoke((Action) delegate { if (Mouse.LeftButton == MouseButtonState.Pressed) { window.DragMove(); } }); }); 编辑:这个黑客工作… window.DragMove(); RaiseEvent(new MouseButtonEventArgs(e.MouseDevice, e.Timestamp, MouseButton.Left) { RoutedEvent = MouseLeftButtonUpEvent }); 谁有更好的?

如何在WPF上使用ICommand的CanExecute方法

首先要说的是我在WPF和MVVM模式的最开始。 在尝试一些自定义命令时,我想知道如何使用ICommand接口中的CanExecute Methode。 在我的例子中,我有一个SaveCommand,我只能在对象可以保存时启用它。 我的保存按钮的XAML代码如下所示: 这是我的保存类的代码: class Save : ICommand { public MainWindowViewModel viewModel { get; set; } public Save(MainWindowViewModel viewModel) { this.viewModel = viewModel; } public bool CanExecute(object parameter) { if (viewModel.IsSaveable == false) return false; return true; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { viewModel.Save(); } } ViewModel中的save属性如下所示: public ICommand […]

WPF自定义形状

我需要创建一个自定义形状以添加到WPF表单上。 形状只是一个三角形。 如果你想知道,是的,我可以用XAML中的Polygon做到这一点: 问题是我们需要绑定一个最终决定形状大小的其他地方的属性。 所以,我写了一个像这样的形状类的简单扩展: public class Triangle:Shape { private double size; public static readonly DependencyProperty SizeProperty = DependencyProperty.Register(“Size”, typeof(Double), typeof(Triangle)); public Triangle() { } public double Size { get { return size; } set { size = value; } } protected override Geometry DefiningGeometry { get { Point p1 = new Point(0.0d,0.0d); Point p2 […]

win 8 metro app c#multiple itemTemplate

我在地铁应用程序上工作,我有情况。 在我的一个页面中,我使用listview和一个显示图像及其名称的自定义项目模板。 现在我必须使用2个项目模板,如果图像是垂直的,我必须使用另一个高度更长的模板。 列表视图中可以有2个不同的模板吗? 我必须更改.cs中的模板, if the image is horizontal listview.ItemTemplate = 1 else if the image is vertical listvew.ItemTemplate =2我该如何使用它?

获取航空窗口颜色

我使用WPF创建了一个非常漂亮的Windows 8-ish界面。 它已经比我希望的方式更好了,但我想知道以下内容: 以某种方式可以检索用户设置的当前窗口颜色吗? 您知道,右键单击桌面时可以设置Aero颜色…我的计划是在GUI上使用该颜色作为几个canvas元素。 提前致谢!

如何在窗口中居中弹出窗口(Windowsapp store应用)

我有一个自定义弹出窗口(作为用户控件),我以编程方式加载。 我无法将其居中于x轴,仅在垂直方向上居中。 弹出窗口未添加到xaml文件中,但会在根窗口中添加。 using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; using System.Windows; using Windows.UI.Core; // The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236 namespace QSTLibrary.WIN8.Tools { public sealed partial class CustomProgressRingPopup : UserControl { public […]

禁用所选Listview项目的蓝色边框

我有一个带有Horizo​​ntal WrapPanel的ListView作为其ItemsPanelTemplate。 我想摆脱所选项目的蓝色背景。 它仅在所选项目的左侧可见。 在SO上有许多类似的问题,我尝试了很多解决方案,但没有一个有效。 这是我已经尝试过的:

WPF旋转按钮

帮帮我吧。 我需要在z轴上旋转按钮,而不使用外部库,只需使用C#和xaml代码。 那可能吗? 我怎样才能做到这一点? 谢谢。

如何绑定窗口的关闭按钮X按钮

如何将控件上的一个按钮绑定到关闭窗口的X按钮? 我只想创建关闭窗口的取消按钮。 我在我的代码中使用MVVM。 如果可能只在xaml中执行,我只是没有任何特殊代码与按钮单击。