2013-05-14 37 views
0

我想制作一个类似于我共享的屏幕。这个想法是从左到右拉项目。我通过WPF工具箱,并没有找到一个完全符合这一点的小部件。或者,这仅仅是一个由2个简单的小部件组成的“辅助工具”。Wpf表单从左到右拉元素

有人能告诉我这是什么类型的小部件,以及如何去做呢?我试图寻找,但想不出拿出好的搜索字词为这个:-((我甚至无法找到此问题的基本好标题)

enter image description here

+2

这是一个只有两个数据网格/列表视图。该按钮从列表1中选取所选项目,并移动(从右边移开,从左边移除)到新列表。 – Jras 2013-05-14 02:27:36

+0

@Jras谢谢。很有用。我会这样做。一旦完成,我会更新。希望我会有一些很好的代码来分享:-) – rockstar 2013-05-14 02:37:41

+0

@RockStar就UX而言,我个人认为界面真的很差,几乎是老技术局限性的解决方法。你为什么不用一个安全/不安全的'ComboBox'或只是一个'CheckBox'来做一个ListBox?我们已经用我们产品的早期版本(VB6 +一些winforms)替换了很多这类的东西,并且使用了CheckBoxes以及类似的东西。 – 2013-05-14 02:49:57

回答

2

有像上面没有预定义的控制,但应该很简单使

这是一个基本的轮廓,让你开始

的XAML:

<Window xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     x:Class="WPFListBoxGroupTest.MainWindow" 
     Title="MainWindow" Height="438" Width="557" x:Name="UI"> 
    <Grid DataContext="{Binding ElementName=UI}" > 
     <Grid.RowDefinitions> 
      <RowDefinition Height="181*"/> 
      <RowDefinition Height="23*"/> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="240*"/> 
      <ColumnDefinition Width="68*"/> 
      <ColumnDefinition Width="241*"/> 
     </Grid.ColumnDefinitions> 
     <Button Content=">>" Grid.Column="1" Command="{Binding AddDevice}" CommandParameter="{Binding SelectedItem, ElementName=unSecure}" HorizontalAlignment="Center" VerticalAlignment="Center" Height="33" Width="48"/> 
     <DockPanel > 
      <TextBox DockPanel.Dock="Top" Text="Unsecured Devices" /> 
      <DataGrid x:Name="unSecure" ItemsSource="{Binding UnsecuredDevices}" /> 
     </DockPanel> 
     <DockPanel Grid.Column="2"> 
      <TextBox DockPanel.Dock="Top" Text="Secured Devices" /> 
      <DataGrid ItemsSource="{Binding SecuredDevices}" /> 
     </DockPanel> 
    </Grid> 
</Window> 

代码:

public partial class MainWindow : Window 
{ 
    private ObservableCollection<Device> _unsecuredDevices = new ObservableCollection<Device>(); 
    private ObservableCollection<Device> _securedDevices = new ObservableCollection<Device>(); 

    public MainWindow() 
    { 
     AddDevice = new RelayCommand(o => SecuredDevices.Add(o as Device), o => o != null); 
     InitializeComponent(); 
     UnsecuredDevices.Add(new Device { Name = "Jonathan Mac", MacAddress = "00:1A:8C:B9:CC" }); 
     UnsecuredDevices.Add(new Device { Name = "Jonathan Mobile", MacAddress = "00:1A:8C:B9:CC" }); 
     UnsecuredDevices.Add(new Device { Name = "Samsung S3", MacAddress = "00:1A:8C:B9:CC" }); 
     UnsecuredDevices.Add(new Device { Name = "BlackBerry BB102", MacAddress = "00:1A:8C:B9:CC" }); 
    } 

    public ICommand AddDevice { get; set; } 

    public ObservableCollection<Device> UnsecuredDevices 
    { 
     get { return _unsecuredDevices; } 
     set { _unsecuredDevices = value; } 
    } 

    public ObservableCollection<Device> SecuredDevices 
    { 
     get { return _securedDevices; } 
     set { _securedDevices = value; } 
    } 
} 

public class Device 
{ 
    public string Name { get; set; } 
    public string MacAddress { get; set; } 
} 

结果:

enter image description here

+0

1+不错的例子。除了Resharper将这些'ObservableCollections'标记为“转换为自动属性”(只是Alt + Enter + Enter + Enter)= P – 2013-05-14 03:13:41

+0

@HighCore,我不使用reshaper,我发现它是有史以来最烦人的扩展VS,但那只是我:) – 2013-05-14 03:32:47

+0

@ sa_ddam213我从来没有想过这么好的例子。太感谢了 。 – rockstar 2013-05-14 03:38:11