-1

I am using DynamicResource in my WPF project but I would like to know how to get it in C# as well, this is how you use it in

XAML:

<Label x:Name="MsgBox_InvoiceCounter" Content="{DynamicResource InvoiceCounterText}" FontSize="15" Margin="10,2,2,0"/>

and as an example I would like to save this now also in the string, how do I do that?:

C#:

string invoiceCounterText = (how do I get this from the DynamicResource??)
Schecher_1
  • 343
  • 4
  • 12

1 Answers1

-1

Depends where you're merging or declaring the resource. It's essentially a string, object dictionary in the resources somewhere.

If you merge in application then.

  var counter = Application.Current.Resources["InvoiceCounterText"] as string;

If you define it in the window or usercontrol then

  var counter = this.Resources["InvoiceCounterText"] as string;
Andy
  • 11,864
  • 2
  • 17
  • 20
  • I know something like this is not desired on stackoverflow, but thanks. You have saved me a lot of work. – Schecher_1 Oct 12 '22 at 19:35
  • 1
    "Depends where you're merging or declaring the resource" - it doesn't matter at all for `TryFindResource()` method – ASh Oct 12 '22 at 19:51