views:

150

answers:

1

I am tired of Windows Forms...I just am. I am not trying to start a debate on it I am just bored with it. Unfortunately we have become dependent on 4 controls in DevExpress XtraEditors. I have had nothing but difficulties with them and I want to move on.

What I need now is what the closet replacement would be for the 4 controls I am using. Here they are:

LookUpEdit - this is a combobox that filters the dropdown list as you type.

MemoExEdit - this is a textbox that 'pops up' a bigger area when it has focus

CheckedComboBoxEdit - this is a dropdown of checkboxes.

CheckedListBoxControl - this is a nicely columned listbox of checkboxes

This is a LOB app that has tons of data entry. In reality, the first two are nice but not essential. The second two are essential in that I would either need to replicate the functionality or change the way the users are interacting with that particular data.

I am looking for help in replicating these in a WPF environment with existing controls(codeplex etc) or in straight XAML. Any code or direction would be greatly appreciated but mostly I am hoping to avoid any commercial 3rd party WPF and would instead like to focus on building them myself(but I need direction) or using Codeplex

+8  A: 

One of the beautiful things about WPF is how easy it is to customize controls (especially when compared to WinForms). Based on the descriptions you've given, all of these controls could be created quite simply with the standard toolbox controls; I don't think you will need to purchase any third-party solutions. Starting from the top:

  1. LookUpEdit- you can get this for free using the WPF combo-box
  2. MemoExEdit- using the standard TextBox control and the Popup primitive, you could duplicate this effect with relatively little effort
  3. CheckedComboBoxEdit- the WPF ComboBox is an ItemsControl, and that means it supports custom item templates. You could do this easily with a couple lines of XAML.
  4. CheckedListBoxControl- same thing for the ListBox, using the ItemTemplate property you can have this going in no time.

Here is a quick example of how you could implement a control resembling the CheckedComboBoxEdit. First, the code-behind:

public partial class CustomControls : Window
{
    public ObservableCollection<CustomItem> Items
    {
        get;
        set;
    }

    public CustomControls()
    {
        Items = new ObservableCollection<CustomItem>();
        Items.Add(new CustomItem() { Name = "Item 1", Checked = true });
        Items.Add(new CustomItem() { Name = "Item 2", Checked = false });
        Items.Add(new CustomItem() { Name = "Item 3", Checked = false });

        InitializeComponent();
    }
}

public class CustomItem
{
    public bool Checked
    {
        get;
        set;
    }

    public string Name
    {
        get;
        set;
    }
}

Now, the XAML for the Window:

<Window x:Class="TestWpfApplication.CustomControls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CustomControls" Height="200" Width="200"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<ComboBox ItemsSource="{Binding Items}" 
          VerticalAlignment="Center"
          HorizontalAlignment="Center"
          Width="100">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Content="{Binding Name}" 
                      IsChecked="{Binding Checked}"/>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

What the ItemTemplate property says is, "for each item in this control, make me one of these." So for every item in the Items collection of the ComboBox, a CheckBox is generated, with its Content bound to the Name property of your item class, and its IsChecked property bound to the Checked property.

And here is the end result:

alt text

Charlie
Really, wow that would be unbelievable...`Item Templates` is something I keep seeing mentioned and it seems I should be looking into it. I'll have to google around. I am guessing that it is what you use to create all thes "composite" controls?
Refracted Paladin
Because WPF has a dynamic content model (fancy way of saying you can stuff any kind of content in just about any place), composite controls are one area it excels in. And yes, item templates are one oft-used method of accomplishing this.
Charlie
@Charlie: So would this all be in a CustomControlLibrary that I would reference in a WPF application? Sorry for the newb questions but when it comes to WPF, I am...
Refracted Paladin
It wouldn't have to be. It could be in-line (i.e. all of the styling and control/data templating can be in the document in which the control appears) you can have the style (which references the template) in a separate custom control (for those that require some coding to make the magic happen) or you can just have a resource dictionary that specifies the styling.Inline hosting of customized controls is hard to maintain, if the control requires some code behind, it is best to have it in a custom Control Library or as a UserControl. If it is just cosmetic change I use resource dictionary.
OffApps Cory