Wpf static binding issue

Ok guys

I have a serious problem with this.

I have a static class with static properties that provides some colors as a hexadecimal string:

namespace com.myCom.Views { public static class MyColorTable { private const string _Hex0 = "#FFFFFFFF"; private const string _Hex1 = "#FFE5E5E5"; public static String Hex0 { get { return _Hex0; } } public static String Hex1 { get { return _Hex1; } } } } 

Now I want to bind these colors to UserControl via XAML, for example:

 <UserControl x:Class="com.testing.MyTestClass" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="53" Width="800" FocusVisualStyle="{x:Null}"> <Grid x:Name="MyGrid" Focusable="false" FocusManager.IsFocusScope="True" Background="{Binding Soure={x:Static MyColorTable}, Path=Hex1}" Margin="0,0,0,0" FocusVisualStyle="{x:Null}" />> 

I know this does not work, so my question is: how do I do it right? I do not need two-way bindings or any PropertyChanged events, since the colors will not be updated after the application starts.

+4
source share
1 answer

got:

 <UserControl x:Class="com.testing.MyTestClass" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:colors="clr-namespace:com.myCom.Views;assembly=com.myCom" Height="53" Width="800" FocusVisualStyle="{x:Null}"> <Grid x:Name="MyGrid" Focusable="false" FocusManager.IsFocusScope="True" Background="{Binding Source={x:Static Member=colors:MyColorTable.Hex1}}" Margin="0,0,0,0" FocusVisualStyle="{x:Null}"/> 
+7
source

Source: https://habr.com/ru/post/1302986/


All Articles