Tag: wpf

WPF TreeViewItem上下文菜单取消亮点项目

我一直有这个问题已经有一段时间了,并提出了一些不太理想的解决方案。 问题是当打开TreeViewItem的上下文菜单时,TreeViewItem将显示为灰色。 TreeViewItem在其ContextMenu打开时是否可以保持突出显示? TreeViewItem变灰的问题在于它与上下文菜单和TreeViewItem没有任何关系,它看起来很难看。 通常,我用于设置上下文菜单的代码是这样的。 有时上下文菜单将由代码使用PreviewRightMouseButtonDown EventSetter生成,但它没有区别: 到目前为止,我发现的唯一解决方案是使用聚焦颜色覆盖“灰色”未聚焦颜色,但是TreeView似乎永远不会聚焦,例如当单击另一个控件时。 我也遇到了ListViews的问题。

使用IValueConverter动态加载图像源

我有IValueconverter的问题并动态加载行网格图像: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string Type = (string)value; Uri uri; try { uri = new Uri(“/XConsole;component/Images/” + Type + “.png”, UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption = BitmapCacheOption.None }; } catch (Exception e) { //donothing } uri = new Uri(“/XConsole;component/Images/Type_SYSTEM.png”, UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption = […]

如何在RichTextBox中找到TextRange(在两个TextPointers之间)

在我的System.Windows.Controls.RichTextBox中,我想找到给定单词的TextRange。 但是,在第一个找到的单词后,它没有给我正确的PositionAtOffset。 第一个是正确的,然后对于下一个找到的单词,位置不正确。 我使用正确的方法吗? 循环遍历listOfWords Word= listOfWords[j].ToString(); startPos = new TextRange(transcriberArea.Document.ContentStart, transcriberArea.Document.ContentEnd).Text.IndexOf(Word.Trim()); leftPointer = textPointer.GetPositionAtOffset(startPos + 1, LogicalDirection.Forward); rightPointer = textPointer.GetPositionAtOffset((startPos + 1 + Word.Length), LogicalDirection.Backward); TextRange myRange= new TextRange(leftPointer, rightPointer);

如何在c#wpf应用程序中绘制具有不同z索引的多行

我正在使用DrawingContext.DrawLine函数来绘制线条。 但似乎线条会影响canvas上其他线条的位置。 所以我需要为所有行添加不同的z-index值。 有没有办法绘制具有不同z-index的线条,因此它们不会影响其他线条的位置。 或者是否有任何其他方法可用于绘制线条,比如绘制文本我用TextBlock替换了DrawText方法。 以下是我现在使用的示例代码: DrawingGroup dGroup = new DrawingGroup(); DrawingContext dc = dGroup.Open() dc.DrawLine(penScaleMarker, new Point((float)newPointX, (float)newPointY), new Point((float)newMinorEndX, (float)newMinorEndY));

在WPF中打印DataGrid中的所有数据

我正在研究WPF应用程序。 我在DataGrid中有数据,我必须打印其中的所有数据。 我试过这个…… publicMainWindow() { InitializeComponent(); DataTabledt = newDataTable(); dt.Columns.Add(“S.No”); dt.Columns.Add(“Name”); dt.Columns.Add(“Father’s Name”); dt.Columns.Add(“DOB”); dt.Columns.Add(“Qualification”); dt.Columns.Add(“Gender”); dt.Columns.Add(“SSC %”); dt.Columns.Add(“+2 %”); dt.Columns.Add(“Graduation %”); dt.Columns.Add(“Work Experience”); dt.Columns.Add(“Company”); object[] rowValues = {“01″,”Gopi”,”Ravi”,”31″,”Degree”,”M”, “88”,”85″, “80”,”2 Years”,”Blah Blah”}; dt.Rows.Add(rowValues); dt.AcceptChanges(); myGrid.DataContext = dt.DefaultView; } privatevoidPrint_Click(object sender, RoutedEventArgs e) { PrintDialogprintDlg = newPrintDialog(); if ((bool)printDlg.ShowDialog().GetValueOrDefault()) { Sizepagesize = newSize(printDlg.PrintableAreaWidth,printDlg.PrintableAreaHeight); myGrid.Measure(pagesize); myGrid.Arrange(newRect(5, […]

ListView InputBinding MouseBinding不起作用

为什么ListView.InputBindings不起作用? 我以相同的方式实现了Interaction.Triggers ,它运行得很好。 真的不想在没有它的情况下使用那些额外的东西( System.Windows.Interactivity for Interaction.Triggers )

如何避免View被处理

我在我的WPF应用程序中使用ContentControl来向用户显示不同的视图 。 通过按下按钮,用户可以将CurrentPageViewModel的值切换到另一个ViewModel对象,并在DataTemplate的帮助下切换到另一个View 。 到现在为止还挺好。 切换视图时,我的问题就开始了。 然后丢弃旧的View ,框架删除/释放View对象。 因此网格排序设置丢失,更糟糕的是,某些视图值设置为空。 空值通过Databinding传播到我的ViewModel ,这完全混淆了我的ViewModel数据! 如何防止删除/丢弃View对象?

你能在最顶层的窗口上启动一个进程吗? (csharp wpf)

你能在最顶层的窗口上启动一个进程吗? (csharp wpf)我有以下内容,但是这个窗口之前的当前窗口(使用具有topmost = true的窗口类的wpf窗口)在启动进程时仍然在进程的顶部。 if (System.IO.File.Exists(MY_CALC_PATH)) { System.Diagnostics.Process helpProcess = new System.Diagnostics.Process(); helpProcess.StartInfo.FileName = “calc.exe”; helpProcess.Start(); helpProcess.WaitForInputIdle(); BringWindowToTop(helpProcess.MainWindowHandle); SetWindowPos(helpProcess.MainWindowHandle, myCurrentTopmostWinHnd, 0, 0, 0, 0, SWP_NOSIZE_); }

如何从WPF WebBrowser获取HtmlElementCollection

我的旧WinForm应用程序使用HtmlElementCollection来处理页面 HtmlElementCollection hec = this.webbrowser.Document.GetElementsByTagName(“input”); 在WPF WebBrowser中,有几个不同的东西。 例如 this.webbrowser.Document没有任何名为GetElementsByTagName的方法 因此我的代码无法获取HtmlElementCollection

将WrapPanel虚拟化为ListView的ItemsTemplate

我的窗口中有一个ListView 。 ListView的默认ItemsPanel已替换为WrapPanel 。 我也有一个DataTemplate用于它的ListViewItem 。 在运行时,主窗口将不会响应一段时间,因为ListView具有超过700(并且不断增加) ListViewItem (来自数据绑定)。 有没有办法让主窗口保持响应? 可选:当ListView没有准备好时,我想要一个文本(或可能的ProgressBar )显示在ListView并说出“Please Wait …”或者“Loading Items …”之类的内容。 XAML: 编辑: 我试过这个: List MyList = new List(); ThreadPool.QueueUserWorkItem(_ => { ( Create MyList here…) Dispatcher.BeginInvoke(new Action(() => { MyListView.ItemsSource = MyList; })); }); 在ListView准备好之前,主窗口仍然没有响应。