I have a SurfaceRadioButton that has to change the Visibility of ScatterView (scatterViewCoordinates)
First, what I have done was to change the Visibility of the object ()
private void CoordinatesChecked(object sender, RoutedEventArgs e)
{
scatterViewCoordinates.Visibility = Visibility.Visible;
}
After that I modified the XAML code, and I included the name of the ScatterView in the Tag value of the SurfaceRadioButton.
<s:SurfaceRadioButton Name="Coordinates" Content="Coordinates"
Checked="CoordinatesChecked" Tag="scatterViewCoordinates" />
Now I was trying to cast the Tag value contained in the SurfaceRadioButton to a ScatterView, and after that to call the Visibility method.
private void CoordinatesChecked(object sender, RoutedEventArgs e)
{
string senderName = ((SurfaceRadioButton)sender).Tag.ToString();
((ScatterView)senderName).Visibility = Visibility.Hidden;
}
And I get this error
Cannot cast expression of type 'string' to type 'ScatterView'
Any ideas to resolve this problem (I don't even now if this respect the MVVM concept :s) ?
Suggestions are welcomed too.
It should be obvious why this does not work, you cannot just cast the name of an object to the object it intrinsically references. There is no way for the program to know what the string means.
How about just passing the object:
Tag="{Binding ElementName=scatterViewCoordinates}"
var view = (ScatterView)((SurfaceRadioButton)sender).Tag;