Reputation: 61
I am trying to get a string from my C# code over to my XAML, but I can't seem to find a way to do it
My C# code
public string demoColour= "#FFFFFF";
My XAML Code
...
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="Bd" Value="{ NOT SURE WHAT GOES HERE :( }"/>
</Trigger>
...
Upvotes: 0
Views: 820
Reputation: 63
As Clemes said, you should take a look at data binding. Data binding is one really important thing in WPF.
But here is one Solution, which works fine:
public string MyColor { get; set; } = "#FFFFFF";
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="{Binding MyColor}"/>
</Style>
</Window.Resources>
Upvotes: 2