wpf-4.0

WPF DataGrid EnableColumnVirtualization=“True” Raises NullReferenceException at DataGridCellsPanel.get_HasCorrectRealizedColumns()

人盡茶涼 提交于 2019-12-23 19:23:14
问题 I have a WPF DataGrid with EnableColumnVirtualization="True" . The user control displays but as soon as you scroll or resize you'll receive a NullReferenceException at DataGridCellsPanel.get_HasCorrectRealizedColumns() . Setting ColumnVirtualization="False" corrects the issue. I've tried removing EnableRowVirtualization="True" ... etc thinking that maybe it was due to a combination of properties but I'm able to reproduce the issue with a very simple DataGrid: <DataGrid ItemsSource="{Binding

WPF 4: What happened to DataGridColumnHeader?

无人久伴 提交于 2019-12-23 09:15:05
问题 What happened to DataGridColumnHeader? It looks like it was dropped when the DataGrid was moved into PresentationFramework. 回答1: DataGridColumnHeader is under the System.Windows.Controls.Primitives namespace in the PresentationFramework.dll assembly. 回答2: Something like <DataGrid ItemsSource="{Binding}"> <DataGrid.Columns> <DataGridTextColumn Header="Column Name" Binding="{Binding Name, Mode=TwoWay}" /> </DataGrid.Columns> </DataGrid> 来源: https://stackoverflow.com/questions/2481946/wpf-4-what

How do you change TemplateBindings to Bindings in a button's control template, without repeating the whole control template

久未见 提交于 2019-12-23 04:52:10
问题 I want to change the background color of a button in its normal, moused-over and pressed states to various shades of green. I am forced to add the following grotesquely verbose Button.Template to my button so that I can modify the RenderMouseOver and RenderPressed attributes to use Binding instead of TemplateBinding , so that my triggers (in the Button.Style ) actually take effect instead of being ignored due to the compile time nature of TemplateBinding . Is there anyway to override these

OneWayToSource Dilemma

本秂侑毒 提交于 2019-12-23 00:25:43
问题 I am using OneWayToSource binding and it seems that it always sets my source property to null. Why is that so? It's causing me troubles because I need value from the target property in my source property and not null. Here is my code: MyViewModel.cs: public class MyViewModel { private string str; public string Txt { get { return this.str; } set { this.str = value; } } } MainWindow.cs: public MainWindow() { InitializeComponent(); MyViewModel vm = new MyViewModel(); vm.Txt = "123"; this

OneWayToSource Dilemma

こ雲淡風輕ζ 提交于 2019-12-23 00:25:33
问题 I am using OneWayToSource binding and it seems that it always sets my source property to null. Why is that so? It's causing me troubles because I need value from the target property in my source property and not null. Here is my code: MyViewModel.cs: public class MyViewModel { private string str; public string Txt { get { return this.str; } set { this.str = value; } } } MainWindow.cs: public MainWindow() { InitializeComponent(); MyViewModel vm = new MyViewModel(); vm.Txt = "123"; this

Strange order of firing of Validation.Error event - Added fired before Removed

落爺英雄遲暮 提交于 2019-12-22 10:58:38
问题 I am getting strange behavior as far as order of firing of Validation.Error event is concerned. According to the documentation here, the data binding engine first removes any ValidationError that may have been added to the Validation.Errors attached property of the bound element . Accordingly, the ValidationErrorEvent for Removed should be fired prior to the Added , but strangely in my case the Added event gets fired before the Removed event. Here is the code that I am using. XAML <TextBox

[WPF]How to draw a grid on canvas?

孤街醉人 提交于 2019-12-21 05:49:15
问题 How to draw the following chart as a background on custom canvas inherited from Canvas - system ui element? Thanks for any useful links. 回答1: You can just set Canvas.Background to some DrawingBrush . This brush can just need to render a Rectangle (by using some RectangleGeometry ). Because of supporting for TileMode , we can repeat this rectangle along both horizontal and vertical axes and make the full grid for you: <Canvas> <Canvas.Background> <DrawingBrush TileMode="Tile" Viewport="-10,-10

0x88980406 SyncFlush() …Is there a workaround?

空扰寡人 提交于 2019-12-21 03:18:12
问题 I get this exception in my application. I have found links discussing it on the web but nothing indicating how to track it down and/or workaround it. Please do not reply with links from the internet. Please reply with strategies of tracking the source. Please reply with workarounds if you found them. Source: PresentationCore Message: Exception from HRESULT: 0x88980406 Stack Trace: at System.Windows.Media.Composition.DUCE.Channel.SyncFlush() at System.Windows.Interop.HwndTarget

Binding to a double with StringFormat on a TextBox

有些话、适合烂在心里 提交于 2019-12-18 13:28:59
问题 I am using WPF's TextBox with a binding on the Text property to a double on my ViewModel. My XAML looks like this: <TextBox Text="{Binding Path=MyDoubleValue, StringFormat=N2, UpdateSourceTrigger=PropertyChanged}" /> Unfortunately when I switch UpdateSourceTrigger to PropertyChanged and type value 12345 , I get 12,354.00 ( EDIT : notice the 5 before the 4). This is a result of keeping cursor in the same place after adding , between 2 and 3 by the .NET formatter. How can I use StringFormat

Disable DataGrid current cell border in FullRow selection mode

…衆ロ難τιáo~ 提交于 2019-12-18 10:58:37
问题 I am using a DataGrid in row selection mode (i.e., SelectionUnit="FullRow" ). I simply want to remove the border that is being placed around the current cell when the user highlights a row in order to have true full row selection (and no cell level selection). I don't mind the notion of the grid maintaining the current cell, I just want to remove that pesky current cell border, perhaps by changing the style of the current cell. What is the easiest way to do this? 回答1: You could set the