Hi, I'm new using MVVM, I need to know How can I execute an event before another one in Silverlight using a RadGridView, for example I have a RadGridView and a TextBox, when I enter something is the textbox and then click in a row, I want to show a message with the text and the id of the selected row.
It just a test, is working by the way but! the problem is when I enter something in my textbox and right after that I click in my RadGridView, is executing the SelectionChanged of the grid before executing the lostfocus of the textbox
This is my xaml:
<
Grid
x:Name
=
"LayoutRoot"
>
<
ScrollViewer
x:Name
=
"PageScrollViewer"
Style
=
"{StaticResource PageScrollViewerStyle}"
>
<
StackPanel
x:Name
=
"ContentStackPanel"
Style
=
"{StaticResource ContentStackPanelStyle}"
>
<
telerik:RadGridView
x:Name
=
"rgvSample"
IsReadOnly
=
"True"
ItemsSource
=
"{Binding LoadRadGridView, Mode=OneWay}"
AutoGenerateColumns
=
"True"
>
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"SelectionChanged"
>
<
i:InvokeCommandAction
Command
=
"{Binding RowIsActiveCommand}"
CommandParameter
=
"{Binding ElementName=rgvSample, Mode=OneWay}"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
</
telerik:RadGridView
>
<!--<TextBox Grid.Column="1" Grid.Row="1" x:Name="myTextBox" Height="25" Text="{Binding AddedText, Mode=TwoWay}" />-->
<
TextBox
Grid.Column
=
"1"
Grid.Row
=
"1"
x:Name
=
"myTextBox"
Height
=
"25"
>
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"LostFocus"
>
<
i:InvokeCommandAction
Command
=
"{Binding TextLostFocusCommand}"
CommandParameter
=
"{Binding ElementName=myTextBox, Path=Text, Mode=TwoWay}"
>
</
i:InvokeCommandAction
>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
</
TextBox
>
</
StackPanel
>
</
ScrollViewer
>
</
Grid
>
and this is my code:
public class RowClickViewModel : ViewModelBase
{
private List<
Item
> _itemList;
public List<
Item
> LoadRadGridView
{
get { return _itemList; }
set { _itemList = value; }
}
private string _addedtext;
public string AddedText
{
get { return _addedtext; }
set
{
if (_addedtext != value)
{
_addedtext = value;
OnPropertyChanged("AddedText");
}
}
}
public RowClickViewModel()
{
LoadRadGridView = GetItems();
}
public ICommand RowIsActiveCommand
{
get
{
return new DelegateCommand(BeginRowIsActive, (o) => true);
}
}
public ICommand TextLostFocusCommand
{
get
{
return new DelegateCommand(BeginLostFocus, (o) => true);
}
}
public void BeginLostFocus(object param)
{
AddedText = param.ToString();
}
public void BeginRowIsActive(object param)
{
Telerik.Windows.Controls.RadGridView myGridView = (Telerik.Windows.Controls.RadGridView)param;
string caption = "Message";
MessageBoxButton buttons = MessageBoxButton.OK;
string message;
message = string.Format("{0}\n{1}", ((Item)(myGridView.SelectedItem)).Name , AddedText);
MessageBox.Show(message, caption, buttons);
}
public List<
Item
> GetItems()
{
return new List<
Item
>
{
new Item { Id = 1, Name = "Item 1" },
new Item { Id = 2, Name = "Item 2" },
new Item { Id = 3, Name = "Item 3" },
new Item { Id = 4, Name = "Item 4" },
new Item { Id = 5, Name = "Item 5" },
new Item { Id = 6, Name = "Item 6" },
new Item { Id = 7, Name = "Item 7" },
new Item { Id = 8, Name = "Item 8" },
new Item { Id = 9, Name = "Item 9" },
new Item { Id = 10, Name = "Item 10" }
};
}
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
}
}
Maybe I'm using the wrong event?
Any help please!!
Thank you.