WPF: Remove dotted border around focused item in styled listbox

You need to set FocusVisualStyle of each ListBoxItem to null. Steps are bellow 1) Create ItemContainerStyle for the ListBox <Style x:Key=”ListBoxItemStyle1″ TargetType=”{x:Type ListBoxItem}”> <Setter Property=”FocusVisualStyle” Value=”{x:Null}”/> …. 2) Set that style to Listbox <ListBox ItemContainerStyle=”{DynamicResource ListBoxItemStyle1}”

Best way to make WPF ListView/GridView sort on column-header clicking?

I wrote a set of attached properties to automatically sort a GridView, you can check it out here. It doesn’t handle the up/down arrow, but it could easily be added. <ListView ItemsSource=”{Binding Persons}” IsSynchronizedWithCurrentItem=”True” util:GridViewSort.AutoSort=”True”> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header=”Name” DisplayMemberBinding=”{Binding Name}” util:GridViewSort.PropertyName=”Name”/> <GridViewColumn Header=”First name” DisplayMemberBinding=”{Binding FirstName}” util:GridViewSort.PropertyName=”FirstName”/> <GridViewColumn Header=”Date of birth” DisplayMemberBinding=”{Binding DateOfBirth}” … Read more

What are the various WPF binding modes?

OneWay: Use this when you want the bound property to update the user interface. TwoWay: This has the same behavior as OneWay and OneWayToSource combined. The bound property will update the user interface, and changes in the user interface will update the bound property (You would use this with a TextBox or a Checkbox, for … Read more

How to use IDataErrorInfo.Error in a WPF program?

You should modify the TextBox style so it shows what’s wrong with the property. Here is a simple example that shows the error as tooltip: <Style TargetType=”TextBox”> <Style.Triggers> <Trigger Property=”Validation.HasError” Value=”true”> <Setter Property=”ToolTip” Value=”{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}” /> </Trigger> </Style.Triggers> </Style> Just put it inside Application.Resources from your app.xaml file and it will be aplied … Read more

Using MS ReportViewer in WPF

Yes, that works, I am using the WindowsFormsHost in a wpf project to wrap the ReportViewer. In the ViewModel I am creating the WindowsFormsHost and the ReportViewer: WindowsFormsHost windowsFormsHost = new WindowsFormsHost(); reportViewer = new ReportViewer(); windowsFormsHost.Child = reportViewer; this.Viewer = windowsFormsHost and in the View I am using a ContentPresenter to display it, by … Read more

Bind an element to two sources

You’re looking for MultiBinding. Your XAML will look something like this: <TextBlock> <TextBlock.Text> <MultiBinding Converter=”{StaticResource myConverter}”> <Binding Path=”myFirst.Value” /> <Binding Path=”mySecond.Value” /> </MultiBinding> </TextBlock.Text> </TextBlock> With reasonable replacements for myConverter, myFirst.Value, and mySecond.Value.

WPF Databind Before Saving

I found that removing the menu items that are scope depended from the FocusScope of the menu causes the textbox to lose focus correctly. I wouldn’t think this applies to ALL items in Menu, but certainly for a save or validate action. <Menu FocusManager.IsFocusScope=”False” >