如下图,这个效果怎么做,点击Add,ListBox中会有一行等待添加,填完鼠标离开自动添加完成,这个效果使用C#怎么来做?
解决方案 »
- 求解释System.Windows.Threading.Dispatcher.Run();
- C#winform 无法关闭窗体
- 谁来帮帮我 C#怎么得到游戏的内存地址 就是金山游侠搜索的地址
- 一个方法里,有个委托调用自己这个方法,该怎么理解?
- 对于字体font。。。如何存储呢? 取出之后如何转换成font
- 初学C#大约要学多长时间啊
- C#里面的dataGridView1 点击上笔和下笔问题
- C#中的动态链接库调用问题?
- 如何实现多用户文件并发传输?
- 用的英文版的vs.net开发环境版本是7。0。9466这是正式版嘛?另外我的.net Fraemework的版本是1.0.3705,但是里面的控件是1。0。3300,这是
- C#中打开excel后,依次读取sheet表,并进行操作
- 想破了头皮,也不知道咋处理这些调休,年假、事假!求助csdn!
<Window x:Class="ListBoxTest.MainWindow"
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/up-compatibility/2006"
xmlns:local="clr-namespace:ListBoxTest"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Background="Gray">
<Window.Resources>
<DataTemplate x:Key="ListBoxTemplate">
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Width="97" Margin="0,5,0,5" FontFamily="Arial" Foreground="Black" FontSize="20" Background="White"/>
</DataTemplate>
<Style TargetType="ListBoxItem" x:Key="ListBoxBack">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF38474E"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FF38474E"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#FF38474E"/>
</Style.Resources>
</Style>
</Window.Resources>
<Grid>
<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="100" BorderThickness="0" Margin="125,80,0,0" VerticalAlignment="Top" Width="100" ItemContainerStyle="{StaticResource ListBoxBack}" ItemsSource="{Binding TextBoxList}" ItemTemplate="{StaticResource ListBoxTemplate}" SelectedIndex="{Binding SelectIndex}"/>
<Button x:Name="AddBtn" Content="Add" HorizontalAlignment="Left" Margin="283,89,0,0" VerticalAlignment="Top" Width="75" Command="{Binding AddCommand}"/>
<Button x:Name="DeleteBtn" Content="Delete" HorizontalAlignment="Left" Margin="283,149,0,0" VerticalAlignment="Top" Width="75" Command="{Binding DeleteCommand}"/>
</Grid>
</Window>MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace ListBoxTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent(); var vm = new MainWindowViewModel();
this.DataContext = vm;
}
}
}MainWindowViewModel.cs:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Prism.ViewModel;
using Microsoft.Practices.Prism.Commands;
using System.Windows.Controls;namespace ListBoxTest
{
public class MainWindowViewModel : NotificationObject
{
private ObservableCollection<TextBox> _textBoxList = new ObservableCollection<TextBox>();
public ObservableCollection<TextBox> TextBoxList
{
get
{
return _textBoxList;
}
set
{
if (_textBoxList != value)
{
_textBoxList = value;
this.RaisePropertyChanged(() => this.TextBoxList);
}
}
} private int _selectIndex = 0;
public int SelectIndex
{
get
{
return _selectIndex;
}
set
{
_selectIndex = value;
this.RaisePropertyChanged(() => this.SelectIndex);
}
} protected DelegateCommand<object> _addCommand = null;
public DelegateCommand<object> AddCommand
{
get
{
if (_addCommand == null)
{
_addCommand = new DelegateCommand<object>(OnAddCommand, CanAddCommand);
}
return _addCommand;
}
} private bool CanAddCommand(object para)
{
return true;
} private void OnAddCommand(object para)
{
Add();
} private void Add()
{
if (TextBoxList != null)
{
TextBoxList.Add(new TextBox { Text = "None"});
}
} protected DelegateCommand<object> _deleteCommand = null;
public DelegateCommand<object> DeleteCommand
{
get
{
if (_deleteCommand == null)
{
_deleteCommand = new DelegateCommand<object>(OnDeleteCommand, CanDeleteCommand);
}
return _deleteCommand;
}
} private bool CanDeleteCommand(object para)
{
return true;
} private void OnDeleteCommand(object para)
{
Delete();
} private void Delete()
{
if (SelectIndex >= 0 && SelectIndex <= TextBoxList.Count)
{
TextBoxList.RemoveAt(SelectIndex);
}
}
}菜鸟瞎写的,里面还有点问题,你看看能不能帮到你
{
InitializeComponent();
listTextBoxs = new List<TextBox>();
} List<TextBox> listTextBoxs;
private void Form2_Load(object sender, EventArgs e)
{
this.flowLayoutPanel1.Dock = DockStyle.Fill;
}
private void button1_Click(object sender, EventArgs e)
{
TextBox t1 = new TextBox(); listTextBoxs.Add(t1); ShowTextBoxs();
} private void button2_Click(object sender, EventArgs e)
{
if (listTextBoxs.Count>0)
{
listTextBoxs.RemoveAt(listTextBoxs.Count - 1);
ShowTextBoxs();
}
} private void ShowTextBoxs()
{
this.flowLayoutPanel1.Controls.Clear();
foreach (TextBox t in listTextBoxs)
{
this.flowLayoutPanel1.Controls.Add(t);
}
}