I am using reflection to set a value of a property, but it is not working! this is because the default color is resetting after! That’s is my code:
MapWindow.xaml:
<Window x:Class="MapRepresentation.MapWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MapWindow" SizeToContent="WidthAndHeight">
<Grid Width="640" Height="739">
<Path x:Name="akkar" Data="..." HorizontalAlignment="Right" Height="124.318" Margin="0,6.482,82.619,0" Stretch="Fill" Stroke="Red" VerticalAlignment="Top" Width="211.881" />
</Grid>
</Window>
MapWindow.Xaml.cs:
public Brush AkkarColor
{
get { return this.akkar.Fill; }
set { this.akkar.Fill = value; }
}
public void ChangeColor()
{
Type type = GetType();
object obj = Activator.CreateInstance(type);
PropertyInfo pathInfo = type.GetProperty("AkkarColor");
pathInfo.SetValue(obj, System.Windows.Media.Brushes.Red, null);
}
private void akkar_MouseEnter(object sender, MouseEventArgs e)
{
ChangeColor();
}
what is wrong ? why the color of the path Akkar is not changing?
It is because you are creating a new instance of the
MapWindow. PassthistoSetValue.