Let’s start from simple introduction. For better understanding my problem I have drastically simplifield this example.
The project is in Silverlight 4. I have got the MainPage.xaml, which consist of a Button:
<Button x:Name="SelectedFillColor" Command="{Binding ChangeColorCommand}" Background="{Binding SelectedColor}">
<Button.Template>
<ControlTemplate>
<Ellipse Width="80" Height="80" Fill="{TemplateBinding Background}" Stroke="White" StrokeThickness="2"/>
</ControlTemplate>
</Button.Template>
</Button>
As you can see I use the ChangeColorCommand command to handle click / touch. In the codebehind of MainPage I just simply bind ViewModel to the DataContext
this.DataContext = new MainPageViewModel();
The last step is my ViewModel which consists of commands initialization method, launched at constructor:
private void InitializeCommands()
{
this.ChangeColorCommand = new RelayCommand(() =>
{
this.SelectedColor = new SolidColorBrush(Colors.Yellow);
});
}
Problem,
when I run this as a web page on my tablet I use two devices:
-
Mouse, when I click on the Ellipse Button then it changes the color to Yellow,
-
Touch, when I tab on the Ellipse Button then it DOES NOT change the color, the default color is present. When I tab again, then the color changes. WHY ???
Thank you
Ok, I found the solution. The problem is with the other control let’s call it TestControl which occurs on the MainPage page. This TestControl control attaches to FrameReported event in its constructor.
So, MainPage supports “Touch events promoted to Mouse events” scenario where the used TestControl uses FrameReported to handle touch. Now, when I commented out this subscription to the FrameReported event, this works as it expected, but I don’t have aswer how to support both scenarios yet.