Click here to Skip to main content
15,891,753 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
i am new to wpf mvvm prism.

Here the items are static items(Not Resumed and Resumption and Cancellation).

current item of combobox is coming from database(i.e one of the static items)



The code is

ActionItems = null;
ActionItems = new O bservableCollection<ViewRequestStatusType>();
ActionType = new ViewRequestStatusType();
ActionType.Id = 1;
ActionType.Type = "Cancellation";
ActionItems.Add(ActionType);
ActionType = new ViewRequestStatusType();
ActionType.Id = 2;
ActionType.Type = "Not Resumed";
ActionItems.Add(ActionType);
ActionType = new ViewRequestStatusType();
ActionType.Id = 3;
ActionType.Type = "Resumption";
ActionItems.Add(ActionType);
ActionType = new ViewRequestStatusType();
ActionType.Id = 0;
ActionType.Type = obj.Data.Action;
ActionItems.Add(ActionType);
var cnt = ActionItems.Count;
ActionItems.Move(cnt - 1, 0);


Xaml code is

<combobox style="{StaticResource ValidateComboBox}" isenabled="{Binding Isshow }" fontsize="25" itemssource="{Binding ActionItems}">
SelectedItem="{Binding ActionType,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"
DisplayMemberPath="Type" Margin="10,0,0,0" SelectedValuePath="Id" IsSynchronizedWithCurrentItem="True"
Height="40" Width="600" />


The output is

Not Resumed
Cancellation
Not Resumed
Resumption

Can anyone please help me

Thanks in advance
Posted

1 solution

xaml:

<window x:class="WpfApplication6.Window1" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<grid>

<stackpanel>
asdf
<combobox itemssource="{Binding Path=PhonebookEntries}">
DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedValue="{Binding Path=PhonebookEntry}" />





namespace WpfApplication6
{
///
/// Interaction logic for Window1.xaml
///

public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
ConnectionViewModel vm = new ConnectionViewModel();
DataContext = vm;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
((ConnectionViewModel)DataContext).PhonebookEntry = "test";
}
}
public class PhoneBookEntry
{
public string Name { get; set; }
public PhoneBookEntry(string name)
{
Name = name;
}
}
public class ConnectionViewModel : INotifyPropertyChanged
{
public ConnectionViewModel()
{
IList<phonebookentry> list = new List<phonebookentry>();
list.Add(new PhoneBookEntry("test"));
list.Add(new PhoneBookEntry("test2"));
_phonebookEntries = new CollectionView(list);
}
private readonly CollectionView _phonebookEntries;
private string _phonebookEntry;

public CollectionView PhonebookEntries
{
get { return _phonebookEntries; }
}

public string PhonebookEntry
{
get { return _phonebookEntry; }
set
{
if (_phonebookEntry == value) return;
_phonebookEntry = value;
OnPropertyChanged("PhonebookEntry");
}
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900