Windows Phone 7 - Can not trigger the event from ViewModel.
source link: https://www.codesd.com/item/windows-phone-7-can-not-trigger-the-event-from-viewmodel.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Windows Phone 7 - Can not trigger the event from ViewModel.
I want to write the event for list box from View Model. I try like this:-
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray" Padding="5" BorderThickness="1">
<StackPanel Orientation="Horizontal">
<Border BorderBrush="Wheat" BorderThickness="1">
<Image Name="ListPersonImage" Source="{Binding PersonImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,0,0,0"/>
</Border>
<TextBlock Text="{Binding FirstName}" Name="firstName" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22" />
<Button DataContext="{Binding DataContext, ElementName=listBox1}" Command="{Binding addPerson}" Height="80" Width="80" >
<Button.Background>
<ImageBrush ImageSource="{Binding imagePath, Converter={StaticResource pathToImageConverter}}" Stretch="Fill" />
</Button.Background>
</Button>
</StackPanel>
</Border>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<i:InvokeCommandAction Command="{Binding ItemSelectedCommand,Mode=OneWay}" CommandParameter="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My ViewModel:-
public RelayCommand<MVVMListBoxModel> ItemSelectedCommand { get; private set; }
public MVVMListBoxViewModel()
{
ItemSelectedCommand = new RelayCommand<MVVMListBoxModel>(ItemSelected);
}
private void ItemSelected(MVVMListBoxModel myItem)
{
MessageBox.Show("Name==>" + myItem.FirstName);
//throw new NotImplementedException();
}
But nothing happening. Please let me know where I did mistake. Thanks in advance.
Check output window to see if you got binding error. It seems that you got one, because you have ItemSelectedCommand
defined in MVVMListBoxViewModel
but ListBoxItem
's DataContext
is corresponding MVVMListBoxModel
, so binding engine couldn't find the command.
Try to move definition of ItemSelectedCommand
to MVVMListBoxModel
and see if message box get displayed this way.
Recommend
-
149
ViewModel 和 LiveData:为设计模式打 Call 还是唱反调?View 层和 ViewModel 层
-
63
1 主要功能Activity、Fragment存活期间的数据存储;bind同一Activity的多个Fragment间数据共享;独立或与LiveData配合实现代码解耦;2 使用方法1) 引...
-
223
[“Cross-Platform Model View ViewModel with Kotlin”]
-
1
Can not connect to the sql server depending on the logon trigger advertisements I have an urgent situation I write a logon trigger for...
-
8
How to create an event in AWS Cloudwatch to trigger a Lambda Function Amazon CloudWatch Events describe changes in AWS resources. We can match events and route them to one or more target functions. CloudWatch Events come to know abo...
-
5
Windows 11’s widgets can now trigger notifications on your taskbar
-
5
digital ethics Flashing content that can trigger seizures World Ethical D...
-
7
Article How OpenShift GitOps notifications can trigger pipelines
-
5
In SAP S/4Hana Cloud, when event for some business object happened like sales order created, some additional logic need to be triggered, for example additional information should be put for this sales order. We can utilized SAP Event Mesh and SAP...
-
4
Can we trigger workflow from custom program even i......
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK