Get the item doubleclick event of listview

<ListView.ItemContainerStyle> <Style TargetType=”ListViewItem”> <EventSetter Event=”MouseDoubleClick” Handler=”listViewItem_MouseDoubleClick” /> </Style> </ListView.ItemContainerStyle> The only difficulty then is if you are interested in the underlying object the listviewitem maps to e.g. private void listViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { ListViewItem item = sender as ListViewItem; object obj = item.Content; }

How to show row-number in first column of WPF Datagrid

There might be an easier way to do this but I got it to work by using the GetIndex() method on the DataGridRow class. This returns the index in to the data source so might not be exactly what you’re after. the xaml <Window x:Class=”WpfApplication1.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:sys=”clr-namespace:System;assembly=mscorlib” xmlns:local=”clr-namespace:WpfApplication1″ Title=”MainWindow” Height=”350″ Width=”525″> <DataGrid> <DataGrid.Columns> <DataGridTextColumn … Read more

Creating a custom-shaped button with one rounded corner

You could use a ControlTemplate to achieve that: <Style x:Key=”ButtonStyle” TargetType=”{x:Type Button}”> <Setter Property=”Background” Value=”Black”/> <Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”{x:Type Button}”> <Path Fill=”{TemplateBinding Background}” Data=”M 0,0 A 100,100 90 0 0 100,100 L 100,100 100,0″ /> </ControlTemplate> </Setter.Value> </Setter> </Style> Than you apply it to the button: <Button Style=”{StaticResource ButtonStyle}”/> If you need some references … Read more

WPF – TabItem Background color changes when tabitem selected or hover over

Here is example of TabItem ControlTemplate Copy it to your resources and set wherever you need Red color as Background. SAMPLE <Window x:Class=”TestCustomTab.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”Window1″ Height=”300″ Width=”300″> <Window.Resources> <SolidColorBrush x:Key=”RedBrush” Color=”Red”/> <SolidColorBrush x:Key=”SolidBorderBrush” Color=”#888″ /> <SolidColorBrush x:Key=”GreenBrush” Color=”Green” /> <SolidColorBrush x:Key=”DisabledBackgroundBrush” Color=”#EEE” /> <SolidColorBrush x:Key=”DisabledBorderBrush” Color=”#AAA” /> <SolidColorBrush x:Key=”DisabledForegroundBrush” Color=”#888″ /> <Style TargetType=”{x:Type TabItem}”> … Read more

Can I use NotifyIcon in WPF?

NotifyIcon is not implemented in WPF as it is in Forms, but you can still use the Windows Form NotifyIcon, it resides in the System.Windows.Forms namspace. Take a look at these tutorials, they might cover your needs: Simple solution, directly using NotifyIcon: http://www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html More advanced solution, new library based on NotifyIcon with more features: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon … Read more

WPF User Control’s DataContext is Null

failing that if you need to check whether the DataContext is being set you can use the DataContextChanged public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); DataContextChanged += new DependencyPropertyChangedEventHandler(UserControl1_DataContextChanged); } void UserControl1_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { // You can also validate the data going into the DataContext using the event args … Read more

WPF ComboBox performance problems by binding a large collections

According to this blog: http://vbcity.com/blogs/xtab/archive/2009/12/15/wpf-using-a-virtualizingstackpanel-to-improve-combobox-performance.aspx I’ve tested it with this code: <ComboBox Name=”cbBlah” ItemsSource=”{Binding}”> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate> </ComboBox.ItemsPanel> </ComboBox> It works fine for first time and next times. It’s not necessary to code these lines: <VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing=”True” VirtualizingStackPanel.VirtualizationMode=”Recycling” />