0

我想制作一个与我分享的类似的屏幕。这个想法是从左到右拉项目。我浏览了 WPF 工具箱,并没有找到完全符合此要求的小部件。或者这只是 2 个简单小部件的组合,其中 >> 充当助手。

有人能告诉我这是什么类型的小部件以及如何去做吗?我尝试搜索,但无法为此找到好的搜索词:-((我什至找不到问题的好标题)

在此处输入图像描述

4

1 回答 1

2

没有像上面这样的预定义控件,但制作起来应该很简单

这是一个让您入门的基本大纲。

xml:

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

结果:

在此处输入图像描述

于 2013-05-14T03:01:12.147 回答