This button click method launches a Window called "(assemblyname).Reports" when a button with Content "Reports" is clicked:
private void Button_Click(object sender, RoutedEventArgs e)
{
Button button = (Button)e.OriginalSource;
Type type = this.GetType();
Assembly assembly = type.Assembly;
Window window = (Window)assembly.CreateInstance(String.Format("{0}.{1}", type.Namespace, button.Content));
window.ShowDialog();
}
But I want the Content attribute value of the button to be able to change, e.g. it might change to "Stock Reports" but I still want the clicking of the button to launch "(assemblyname).Reports".
Is there a way to add attributes to the button tag, e.g. "TheWindowFileName"?
<Button x:Name="btnReports" Content="Stock Reports" TheWindowFileName="Reports"/>
If not, how else can I add additional information to my button elements which I can read and process in code behind?
Certainly you can use attached properties to add extra attributes to XAML elements, but for what you need you could probably just use the existing Tag property:
<Button x:Name="btnReports" Content="Stock Reports" Tag="Reports"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With