Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

AutoCompleteBox not displaying initial value

$
0
0

The WPF Toolkit AutoCompleteBox is not showing the initial value. If the user types in the it searches and update the value and displays the new value. A ComboBox and TextBlock bound to the same ItemsSource and SelectedItem displays correctly. I using WPF Toolkit 3.5.40128.1 in a .Net V4 WPF application with VS 2010

Thanks

Sample

 

<Windowxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:Toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"xmlns:local="clr-namespace:WpfApplication1"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"x:Class="WpfApplication1.MainWindow"Title="MainWindow"Height="350"Width="525"><Window.Resources><local:ViewModelx:Key="ViewModelDataSource"d:IsDataSource="True"/></Window.Resources><Window.DataContext><BindingMode="OneWay"Source="{StaticResource ViewModelDataSource}"/></Window.DataContext><Grid><Grid.RowDefinitions><RowDefinitionHeight="26*"/><RowDefinitionHeight="26*"/><RowDefinitionHeight="259*"/></Grid.RowDefinitions><Toolkit:AutoCompleteBoxItemsSource="{Binding Items}"SelectedItem="{Binding SelectedItem, Mode=TwoWay}"ValueMemberPath="Name"><Toolkit:AutoCompleteBox.ItemTemplate><DataTemplate><TextBlockText="{Binding Name}"/></DataTemplate></Toolkit:AutoCompleteBox.ItemTemplate></Toolkit:AutoCompleteBox><ComboBoxItemsSource="{Binding Items}"SelectedItem="{Binding SelectedItem}"DisplayMemberPath="Name"Grid.Row="1"/><TextBlockGrid.Row="2"Text="{Binding SelectedItem.Name}"/></Grid></Window>

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ComponentModel;namespace WpfApplication1 {publicclass ViewModel : INotifyPropertyChanged {public ViewModel() {
      Items = new List<Item>();
      Items.Add(new Item() { MyID = 1, Name = "aaa" });
      Items.Add(new Item() { MyID = 2, Name = "bbb" });
      Items.Add(new Item() { MyID = 3, Name = "ccc" });
      Items.Add(new Item() { MyID = 4, Name = "ddd" });
      Items.Add(new Item() { MyID = 5, Name = "eee" });
      SelectedItem = Items[0];
    }public List<Item> Items { get; set; }public Item _Item;public Item SelectedItem {get { return _Item; }set {if (_Item != value) {
          _Item = value;
          RaisePropertyChanged("SelectedItem");
        }
      }
    }publicevent PropertyChangedEventHandler PropertyChanged;internalvoid RaisePropertyChanged(String info) {if (PropertyChanged != null) {
        PropertyChanged(this, new PropertyChangedEventArgs(info));
      }
    }
  }publicclass Item {publicint MyID { get; set; }publicstring Name { get; set; }
  }
}

 


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>