WPF ListView ScrollBar visible to false

You can specify the visibility of the scrollbar for both vertical and horizontal scrolling to four options, using the ScrollViewer.HorizontalScrollBarVisibility and ScrollViewer.VerticalScrollBarVisibility attached properties: Auto, Disabled, Hidden and Visible. <ListView ScrollViewer.HorizontalScrollBarVisibility=”Disabled”> Disabled will have it never show up and scrolling is not possible, Hidden will have it not show, but will allow users to scroll … Read more

How to capture a mouse click on an Item in a ListBox in WPF?

I believe that your MouseLeftButtonDown handler is not called because the ListBox uses this event internally to fire its SelectionChanged event (with the thought being that in the vast majority of cases, SelectionChanged is all you need). That said, you have a couple of options. First, you could subscribe to the PreviewLeftButtonDown event instead. Most … Read more

WPF DataGrid: CommandBinding to a double click instead of using Events

No need for attached behaviors or custom DataGrid subclasses here. In your DataGrid, bind ItemsSource to an ICollectionView. The trick here is to set IsSynchronizedWithCurrentItem=”True” which means the selected row will be the current item. The second part of the trick is to bind CommandParameter to the current item with the forward slash syntax. When … Read more

Printing a WPF FlowDocument

yes, make a copy of the FlowDocument before printing it. This is because the pagination and margins will be different. This works for me. private void DoThePrint(System.Windows.Documents.FlowDocument document) { // Clone the source document’s content into a new FlowDocument. // This is because the pagination for the printer needs to be // done differently than … Read more

Declaring Text Decorations such as Underline, Strikethrough in a Style

Underlining text can be done either with <Underline>…</Underline> or with the TextDecorations attribute set to Underline. You can include the latter in a style definition: <Style x:Key=”Underlined”> <Setter Property=”TextBlock.TextDecorations” Value=”Underline” /> </Style> <TextBlock Style=”{StaticResource Underlined}”> Foo </TextBlock>

What is the actual task of CanExecuteChanged and CommandManager.RequerySuggested?

CanExecuteChanged notifies any command sources (like a Button or MenuItem) that are bound to that ICommand that the value returned by CanExecute has changed. Command sources care about this because they generally need to update their status accordingly (eg. a Button will disable itself if CanExecute() returns false). The CommandManager.RequerySuggested event is raised whenever the … Read more