Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to replace 3rd party WinForm controls, what's the closet WPF equivalent?

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

like image 446
Refracted Paladin Avatar asked Jan 22 '23 04:01

Refracted Paladin


1 Answers

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 http://img155.imageshack.us/img155/9379/customcontrols.png

like image 192
Charlie Avatar answered Apr 30 '23 05:04

Charlie