WPF Editable ComboBox

Here’s a basic MVVM compliant way of getting the behaviour you want: MainWindow.xaml <Window x:Class=”WpfApplication1.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”MainWindow” Height=”350″ Width=”525″> <StackPanel> <ComboBox Margin=”30,5,30,5″ IsEditable=”True” ItemsSource=”{Binding Items}” SelectedItem=”{Binding SelectedItem}” Text=”{Binding NewItem, UpdateSourceTrigger=LostFocus}”/> <TextBox Margin=”30,5,30,5″ /> </StackPanel> </Window> MainWindow.cs public partial class MainWindow : Window, INotifyPropertyChanged { private string _selectedItem; private ObservableCollection<string> _items = new ObservableCollection<string>() { … Read more

wpf custom button best approach

Like you, when I was getting started and wanted to understand how / what was going on and working with templates, it took a lot of trial and error. Hopefully my research and some step-by-step components can help you customize to your liking and KNOWING where things are coming from. First, when trying to understand … Read more

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

WPF ListView with GridViewColumn and DataTemplate

You need to define the data template as CellTemplate for your column: <ListView x:Name=”lbDatabases” Height=”138″ Width=”498″ Canvas.Left=”44″ Canvas.Top=”146″ > <ListView.View > <GridView > <GridViewColumn Header=”Databases” Width=”498″> <GridViewColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked=”{Binding IsActive}” Checked=”AnyChange” Unchecked=”AnyChange” Style=”{x:Null}” Content=”{Binding DbName}” Width=”{Binding CheckWidth}” /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView>

How do I dynamically bind and statically add MenuItems?

You can use a CompositeCollection to do this, you can combine different Collections and add static items in the xaml. Example: Xaml: <Window x:Class=”WpfApplication8.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”MainWindow” Height=”233″ Width=”143″ Name=”UI”> <Window.Resources> <CollectionViewSource Source=”{Binding ElementName=UI, Path=Windows}” x:Key=”YourMenuItems”/> </Window.Resources> <Grid DataContext=”{Binding ElementName=UI}”> <Menu Height=”24″ VerticalAlignment=”Top”> <MenuItem Header=”_View” > <MenuItem Header=”Windows”> <MenuItem.ItemsSource> <CompositeCollection> <CollectionContainer Collection=”{Binding Source={StaticResource YourMenuItems}}” /> … Read more