Reputation: 1354
I try to access a static member in XAML but the compiler keeps complaining. Can anyone help.
This is the XAML
<Window x:Class="tt_WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:tt_WPF"
Title="MainWindow" SizeToContent="WidthAndHeight">
<Button Content="{x:Static local:MainWindow.SomeString}" />
</Window>
This is the code behind
namespace tt_WPF
{
public partial class MainWindow : Window
{
public static string SomeString = "Hello";
public MainWindow()
{
InitializeComponent();
}
}
}
Upvotes: 1
Views: 418
Reputation: 13907
Your code works perfectly fine as-is, with no changes.
If it won't let you compile, I'd recommend doing a Clean Solution and restarting Visual Studio. If that doesn't work, try creating a new WPF project and copying your code in, incase some other file is messed up.
Upvotes: 1