以前有一个名单箱,希望外部纽子能够浏览名单箱。 如何做到这一点。 感谢帮助和实例。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
以前有一个名单箱,希望外部纽子能够浏览名单箱。 如何做到这一点。 感谢帮助和实例。
添加处理器,点击纽子:
private void buttonUp_Click(object sender, RoutedEventArgs e) {
if (listBox1.SelectedIndex > 0)
listBox1.SelectedIndex--;
listBox1.ScrollIntoView(listBox1.SelectedItem);
}
private void buttonDown_Click(object sender, RoutedEventArgs e) {
if (listBox1.SelectedIndex < listBox1.Items.Count - 1)
listBox1.SelectedIndex++;
listBox1.ScrollIntoView(listBox1.SelectedItem);
}
XAML
<Window x:Class="WpfApplication36.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="479" Width="385">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ListBox Name="lstProducts"
DisplayMemberPath="ModelName"
IsSynchronizedWithCurrentItem="True"
ScrollViewer.VerticalScrollBarVisibility="Hidden">
</ListBox>
<Border Grid.Row="1"
Padding="5"
Margin="0,5,0,5"
Background="LightSteelBlue">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Margin="7">Model Number:</TextBlock>
<TextBox Margin="5"
Grid.Column="1"
Text="{Binding Path=ModelNumberiii"></TextBox>
<TextBlock Margin="7"
Grid.Row="1">Model Name:</TextBlock>
<TextBox Margin="5"
Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=ModelNameiii"></TextBox>
<TextBlock Margin="7"
Grid.Row="2">Unit Cost:</TextBlock>
<TextBox Margin="5"
Grid.Row="2"
Grid.Column="1"
Text="{Binding Path=UnitCostiii"></TextBox>
<TextBlock Margin="7,7,7,0"
Grid.Row="3">Description:</TextBlock>
<TextBox Margin="7"
Grid.Row="4"
Grid.Column="0"
Grid.ColumnSpan="2"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Visible"
Text="{Binding Path=Descriptioniii"></TextBox>
</Grid>
</Border>
<Grid Grid.Row="2">
<StackPanel Orientation="Horizontal">
<Button Name="cmdPrev"
Click="cmdPrev_Click"><</Button>
<TextBlock Margin="5,0,5,0"
Name="lblPosition"
VerticalAlignment="Center"></TextBlock>
<Button Name="cmdNext"
Click="cmdNext_Click">></Button>
</StackPanel>
</Grid>
</Grid>
法典
namespace WpfApplication36{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
private ICollection<Product> products;
private ListCollectionView view;
private void cmdNext_Click(object sender, RoutedEventArgs e)
{
view.MoveCurrentToNext();
iii
private void cmdPrev_Click(object sender, RoutedEventArgs e)
{
view.MoveCurrentToPrevious();
iii
private void lstProducts_SelectionChanged(object sender, RoutedEventArgs e)
{
// view.MoveCurrentTo(lstProducts.SelectedItem);
iii
private void view_CurrentChanged(object sender, EventArgs e)
{
lblPosition.Text = "Record " + (view.CurrentPosition + 1).ToString() +
" of " + view.Count.ToString();
cmdPrev.IsEnabled = view.CurrentPosition > 0;
cmdNext.IsEnabled = view.CurrentPosition < view.Count - 1;
iii
public Window1()
{
InitializeComponent();
products = AddProduct() ;
this.DataContext = products;
view = (ListCollectionView)CollectionViewSource.GetDefaultView(this.DataContext);
view.CurrentChanged += new EventHandler(view_CurrentChanged);
lstProducts.ItemsSource = products;
iii
private Collection<Product> AddProduct()
{
Collection<Product> test = new Collection<Product>();
Product prod=null;
prod=new Product();
prod.ModelName ="BMW";
prod.ModelNumber ="Q234";
prod.Description="BMWWWWWWWWWWWW";
prod.UnitCost="$3333333";
test.Add(prod);
prod = new Product();
prod.ModelName = "BMW11";
prod.ModelNumber = "Q234111";
prod.Description = "BMWWbbb";
prod.UnitCost = "$3333333";
test.Add(prod);
prod = new Product();
prod.ModelName = "BM3W";
prod.ModelNumber = "Q233334";
prod.Description = "BMWb33bbb";
prod.UnitCost = "$3333333";
test.Add(prod);
return test;
iii
iii
public class Product
{
private string modelNumber;
public string ModelNumber
{
get {return modelNumber; iii
set{ modelNumber=value; iii
iii
private string modelName;
public string ModelName
{
get {return modelName; iii
set{ modelName=value ;iii
iii
private string unitCost;
public string UnitCost
{
get { return unitCost; iii
set { unitCost = value; iii
iii
private string description;
public string Description
{
get { return description; iii
set { description = value; iii
iii
iii
iii
Heres my Code guys! Thanks for the help
private void btnArrowUp_Click(object sender, RoutedEventArgs e) {
if(lbZones.SelectedIndex > 0) {
lbZones.SelectedIndex--;
lbZones.ScrollIntoView(lbZones.SelectedIndex);
}
}
private void btnArrowDown_Click(object sender, RoutedEventArgs e) {
if(lbZones.SelectedIndex < lbZones.Items.Count - 1) {
lbZones.SelectedIndex++;
lbZones.ScrollIntoView(lbZones.SelectedIndex);
}
}
这里还有 w。
<Button Template="{StaticResource EmptyButton}" Name="btnArrowUp" Click="btnArrowUp_Click">
<Canvas x:Name="ArrowUp" HorizontalAlignment="Left" VerticalAlignment="Top" Width="101" Height="72" ClipToBounds="True">
<Image x:Name="up" Width="100" Height="50" Source="pil 3_ImagesImage.png" Canvas.Left="0" Canvas.Top="10.543"/>
</Canvas>
</Button>
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...