C# WPF: Setting Resource Values Dynamically (MAC Address Example)
The code you provided is incorrect as it tries to assign a value to a resource property directly, which is not possible. \r\n\r\nTo set a value for a resource in C# WPF, you need to use the Application.Current.Resources dictionary. Assuming you have a resource named "MACAddress" declared in your XAML, you can set its value in code-behind as follows:\r\n\r\ncsharp\r\nstring macAddress = \"Your MAC Address\";\r\nApplication.Current.Resources[\"MACAddress\"] = macAddress;\r\n\r\n\r\nAfter setting the value, you can access it in your XAML using the StaticResource markup extension:\r\n\r\nxaml\r\n<TextBlock Text="{StaticResource MACAddress}" />\r\n\r\n\r\nMake sure to replace "Your MAC Address" with the actual MAC address you want to set.
原文地址: https://www.cveoy.top/t/topic/pvh2 著作权归作者所有。请勿转载和采集!