Tag: wpf

WPF绑定到变量/ DependencyProperty

我正在玩WPF Binding和变量。 显然,只能绑定DependencyProperties。 我提出了以下内容,它完全正常:代码隐藏文件: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public string Test { get { return (string)this.GetValue(TestProperty); } set { this.SetValue(TestProperty, value); } //set { this.SetValue(TestProperty, “BBB”); } } public static readonly DependencyProperty TestProperty = DependencyProperty.Register( “Test”, typeof(string), typeof(MainWindow), new PropertyMetadata(“CCC”)); private void button1_Click(object sender, RoutedEventArgs e) { […]

WPF ComboBox MaxDropDownItems

无论如何设置下拉项的最大数量而不是WPF中的最大下拉高度? 谢谢! -Kevin

如何在非UI线程中编辑WritableBitmap.BackBuffer?

我的应用程序运行CPU重的algorythms编辑放置在WPF窗口的图像。 我需要在后台线程中完成编辑。 但是,尝试在非UI线程中编辑WritableBitmap的BackBuffer会引发InvalidOperationException。 private WriteableBitmap writeableBitmap; private void button1_Click(object sender, RoutedEventArgs e) { // Create WritableBitmap in UI thread. this.writeableBitmap = new WriteableBitmap(10, 10, 96, 96, PixelFormats.Bgr24, null); this.image1.Source = this.writeableBitmap; // Run code in non UI thread. new Thread( () => { // ‘Edit’ bitmap in non UI thread. this.writeableBitmap.Lock(); // Exception: The calling […]

WPF RichTextBox语法突出显示问题

大家好我一直在研究一个带有文本编辑器的WPF应用程序这个文本编辑器应该应用一些样式或着色一些标记(关键字)来突出显示它并使其显而易见,,,问题是我非常努力但是我仍然得到相同的结果,即用户在关键字被设置样式后输入整个文本中的一个关键字! 试想一下,如果你在“C#”中键入“string”关键字,它之后的整个文字将会变成蓝色。 这是我使用的代码: static List tags = new List(); static List specials = new List(); static string text; #region ctor static MainWindow() { string[] specialWords = { “string”, “char”, “null” }; tags = new List(specialWords); // We also want to know all possible delimiters so adding this stuff. char[] chrs = { ‘.’, ‘)’, ‘(‘, […]

可以将DirectX表面绘制到WPF控件吗?

DirectX可用于绘制WPF控件上的一组点(或WPF可以使用的东西)。 我需要在WPF中实现一个控件,该控件应该以30 Hz的更新率绘制16k点,现在我的解决方案已经用完了。 这个想法来自这个问题的评论。 任何帮助将非常感激。

使用C#,WPF和DWM保存窗口的屏幕截图

这是对这个问题的后续问题 上述解决方案使用DWM显示活动窗口的缩略图。 如果我理解正确,它的工作原理是让你指定要查看的应用程序的窗口句柄,然后让你提供一个窗口句柄和窗口上应该绘制目标窗口内容的位置。 有没有办法将窗口屏幕直接渲染到BitmapImage或Image而不是直接在窗口中的某个位置绘制? (基本上只是抓住窗口的屏幕截图 – 即使它被另一个窗口覆盖 – 没有使用更新缩略图。) 谢谢你的帮助!

窗口在WPF中显示事件?

我想在每次显示窗口时应用淡入淡出动画。 如何从xaml做到这一点? 该窗口可以隐藏然后再次显示,因此我无法使用Loaded事件。

将ResourceDictionary添加到类库

我创建了一个类库,它包含WPF Windows和一些从我的c#类inheritance的用户控件,可以帮助我自定义某些wpf控件。 现在我想添加ResourceDictionary,以帮助我在我的wpf类之间共享样式。 可能吗? 谢谢。 编辑:位于MY.WpfPresentation.Main项目(名为Styles.xaml)的资源字典文件: 使用它:

减少位图调色板中颜色数量的最佳方法

我有一个包含很多不同颜色的位图。 但我需要用这种图像制作一个40色或更少颜色的方案。 这就是为什么我需要方法来减少位图调色板中的颜色数量。 我正在使用下面的代码为我的应用程序: using System.Windows.Media.Imaging; //BitmapSource ================================================== //Create palette of requied color. Pay heed to maxColorCount it //can have any value, but PixelFormats supports only 2,4,16 and 256 colors. var myPalette = new BitmapPalette(ConvertBitmap(b) as BitmapSource, 16); newFormatedBitmapSource.DestinationPalette = myPalette; //Set PixelFormats newFormatedBitmapSource.DestinationFormat = PixelFormats.Indexed8; newFormatedBitmapSource.EndInit(); b = BitmapFromSource(newFormatedBitmapSource); 它可以工作,但很多时候我会在较暗的颜色的大部分固体背景上收到带有明亮像素的图像: 我试着自己做:最近的4或9像素(正方形)并混合它。 我还尝试减少位图大小并“拉伸”位图。 最后我试图吸收最近的颜色。 但是我用上面的方法得到的最好的结果。 […]

如何获取当前ItemsControl项的索引?

有没有办法获取WPF当前ItemsControl项的索引? 例如,我想做类似的事情: 这样,在此之后,第一个TextBox将显示文本”0″ ,第二个”1″ ,第三个”2″ …