Well, I have a control that inherits usercontrol (view) and im using it since you are using usercontrol (the base control), now the problem is if I do
MessageBox.Show(this.GetType().ToString());
I get different messages at runtime and development time, during development I get View and I runtime. I get the class name of the xaml file inheriting the view ...
How can I get the type of an inherited class at design time instead of the base class?
Here is the code:
First we have the class Class
public class View : UserControl { public override void OnApplyTemplate() { MessageBox.Show(this.GetType().ToString()); base.OnApplyTemplate(); } }
Then we have the XAML file:
<local:View x:Class="WpfApplication2.Test" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WpfApplication2" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> </Grid> </local:View>
Now, if you compile and open "WpfApplication2.Test" in VisualStudio 2010, you will get a window with the message "WpfApplication2.View" ..
But if you put the control in your MainWindow and press Run (F5), you get WpfApplication2.Test .. what I want should have the same answer at design time that I have at runtime ...
c # xaml design-time
Peter
source share