Hi!
I use this Service:
public Service()
{
BList = new ObservableCollection<object>()
{new CommonData() { MenuName="name1",Id="s01"}
,new BOption() {MenuName="nam2"}
,new BOption(){MenuName="nam3"}};
}
public ObservableCollection<object> BList { get; private set; }
Then this ViewModel:
public class CommonScreenViewModel
{
public ViewModel(IService Service)
{
this.Service=Service;
this.ImportCommand = new DelegateCommand<object>(this.OnImport, this.CanImport);
}
public IService Service;
public ICommand ImportCommand { get; private set; }
private void OnImport(object arg) {
MessageBox.Show("Importing...");
}
private bool CanImport(object arg) { return true; }
}
I set the dataContext in the View.xaml.cs like this:
public View(ViewModel viewModel)
{
InitializeComponent();
this.Loaded += (s, e) =>
{ this.DataContext = viewModel; };
}
In the XAML file i want to do some binding like this:
<Button Content="Command" IsEnabled="{Binding CanImport}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding ImportCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBox Text="{Binding Path=Service.BList[0].Id, Mode=TwoWay}"/>
My problem is that the Button Binding works fine but the textbox does not.
If I change the view.xaml.cs to
public View(ViewModel viewModel)
{
InitializeComponent();
this.Loaded += (s, e) =>
{ this.DataContext = viewModel.Service.BList[0]; };
}
and bind my textbox with just
<TextBox Text="{Binding Path=Id, Mode=TwoWay}"/>
then the TextBox binds fine but the button doen't work
Any suggestions? (thnx in advance)