• Silverlight学习笔记九ListBox控件


    ListBox是SilverLight列表控件

    1.ListBoxDemo.xaml

    <UserControl x:Class="Silverlight.Common.View.ListBoxDemo"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                   xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:toolKit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">

        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" FlowDirection="LeftToRight">
                <CheckBox Content="是否允许拖动" x:Name="IsdragDrop" IsChecked="True" Click="CheckBox_Click"></CheckBox>
                <TextBox x:Name="txtSelectValue" Text="SelectValue" Margin="3"></TextBox>
                <TextBox x:Name="txtSelectItem" Text="SelectItem" Margin="3"></TextBox>
                <TextBlock Text="显示项:"></TextBlock>
                    <ComboBox HorizontalAlignment="Left" Width="auto" SelectedItem="{Binding DisplayMemberPath, ElementName=listBox, Mode=TwoWay}" Margin="4" SelectedIndex="2">
                    <sys:String>Name</sys:String>
                    <sys:String>IsEnabled</sys:String>
                    <sys:String>UserID</sys:String>
                </ComboBox>
       
            </StackPanel>
            <toolKit:ListBoxDragDropTarget  x:Name="dragDrop1" AllowDrop="True" Grid.Column="1">
                <ListBox Height="200" Width="200"  x:Name="listBox" ItemsSource="{Binding}" DisplayMemberPath="Name">
                  
                </ListBox>
            </toolKit:ListBoxDragDropTarget>
            <toolKit:ListBoxDragDropTarget  x:Name="dragDrop2" AllowDrop="True" Grid.Column="2">
                <ListBox Height="200" Width="200" DisplayMemberPath="Name">
                 
                </ListBox>
            </toolKit:ListBoxDragDropTarget>
        </Grid>
    </UserControl>

    2.ListBoxDemo.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Silverlight.Common.Core;

    namespace Silverlight.Common.View
    {
        public partial class ListBoxDemo : UserControl
        {
            public ListBoxDemo()
            {
                InitializeComponent();
                this.DataContext = UserList.GetUserList();
            }

            private void CheckBox_Click(object sender, RoutedEventArgs e)
            {
                if (!(bool)this.IsdragDrop.IsChecked)
                {
                    this.dragDrop1.AllowDrop = false;
                    this.dragDrop2.AllowDrop = false;
                 
                }

                else
                {
                    this.dragDrop1.AllowDrop = true;
                    this.dragDrop2.AllowDrop = true;
                }

            }

            private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (this.listBox.SelectedValue!=null)
                {
                 User user=this.listBox.SelectedValue as User;
                 this.txtSelectValue.Text = user.Name;
                }

                if (this.listBox.SelectedItem != null)
                {
                    User user = this.listBox.SelectedItem as User;
                    this.txtSelectItem.Text = user.Name;
                }
            }
        }
    }

     注:DisplayMemberPath是ListBox的显示项,通过改变这个属性,来改变所显示对象的属性。

  • 相关阅读:
    14.3.2.1 Transaction Isolation Levels 事务隔离级别
    ReentrantLock可重入锁
    Lock与synchronized 的区别
    synchronized 与 Lock
    This usually indicates a missing no-arg constructor or that the editor's class name was mistyped in
    Oracle dump 分析secondary key
    java.lang.ClassNotFoundException: org.springframework.web.util.IntrospectorCleanupListener
    Oracle 验证IOT表数据存储在主键里
    Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for U
    Oracle heap 表的主键 dump 分析
  • 原文地址:https://www.cnblogs.com/salam/p/1776662.html
Copyright © 2020-2023  润新知