需要替换第 3 方 WinForm 控件,最接近的 WPF 等效项是什么?

发布于 2024-08-31 04:37:06 字数 879 浏览 3 评论 0原文

我厌倦了 Windows 窗体...我就是厌倦了。我并不是想就此展开辩论,我只是对此感到厌倦。不幸的是,我们已经开始依赖 DevExpress XtraEditors 中的 4 个控件。 除了与他们相处遇到困难之外什么都没有,我想继续前进。

我现在需要的是用壁橱替换我正在使用的 4 个控制器。它们是:

LookUpEdit - 这是一个组合框,可在您键入时过滤下拉列表。

MemoExEdit - < em>这是一个文本框,当获得焦点时会“弹出”更大的区域

CheckedComboBoxEdit - 这是一个复选框的下拉列表.

CheckedListBoxControl - 这是一个由复选框组成的精美列列表框

这是一个LOB 应用程序具有大量数据输入。事实上,前两个很好,但不是必需的。后两个至关重要,因为我要么需要复制功能,要么改变用户与特定数据交互的方式。

我正在寻求帮助,以在具有现有控件(codeplex 等)的 WPF 环境中或在直接 XAML。任何代码或方向将不胜感激,但大多数情况下我希望避免任何商业第 3 方 WPF,而是希望专注于自己构建它们(但我需要方向)或使用 Codeplex

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲琵琶半遮面シ 2024-09-07 04:37:06

WPF 的优点之一是自定义控件非常容易(尤其是与 WinForms 相比)。根据您给出的描述,所有这些控件都可以使用标准工具箱控件非常简单地创建;我认为您不需要购买任何第三方解决方案。从顶部开始:

  1. LookUpEdit - 您可以使用 WPF 组合框 MemoExEdit 免费获得此内容
  2. - 使用标准 TextBox 控件和 < code>Popup 原语,您可以用相对较少的努力复制此效果
  3. CheckedComboBoxEdit - WPF ComboBox 是一个 ItemsControl,并且意味着它支持自定义项目模板。您可以使用几行 XAML 轻松完成此操作。
  4. CheckedListBoxControl - 对于 ListBox 来说也是如此,使用 ItemTemplate 属性您可以立即完成此操作。

下面是一个简单示例,说明如何实现类似于 CheckedComboBoxEdit 的控件。首先,代码隐藏:

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;
    }
}

现在,Window 的 XAML:

<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>

ItemTemplate 属性的意思是,“对于此控件中的每个项目,将我设为其中之一。”因此,对于 ComboBoxItems 集合中的每个项目,都会生成一个 CheckBox,其 Content 绑定到项目类的 Name 属性,及其绑定到 Checked 属性的 IsChecked 属性。

这是最终结果:

alt text http://img155.imageshack.us/img155/9379/customcontrols.png

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文