我正在尝试将边框笔刷颜色绑定到实用程序文件的管理属性。引用非静态类中的静态类的静态属性的语法是什么?
<Window x:Class="Company.FieldServiceManagement.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FieldServiceManagement"
xmlns:util="clr-namespace:Company.Utilities;assembly=Comp_Utilities"
mc:Ignorable="d"
Title="Field Service Management - Stand Alone" Height="750" MinHeight="500" Width="950" MinWidth="950">
<Window.Resources>
<util:ApplicationVariables x:Key="apv" />
</Window.Resources>
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="BorderThickness" Value="3"/>
<Setter Property="BorderBrush" Value="{Binding Source={StaticResource apv}, Path=Colors.Management}"/>
</Style>
</Window.Style>
<Grid>
<ContentControl x:Name="mainContentControl"/>
</Grid>
</Window>
来自实用程序DLL程序集:
namespace Company.Utilities
{
public class ApplicationVariables
{
public static class Colors
{
public static Color Employee { get; } = Color.FromArgb(192, 255, 192);
public static Color Management { get; } = Color.FromArgb(255, 224, 192);
public static Color HumanResources { get; } = Color.FromArgb(255, 192, 192);
public static Color Payroll { get; } = Color.FromArgb(192, 255, 255);
public static Color Rerpoting { get; } = Color.FromArgb(255, 192, 255);
}
}
}
您不需要任何类的实例即可访问static
成员。
Colors
属性似乎也没有改变,因此可以使用Binding
扩展名代替{x:Static}
:
<Setter Property="BorderBrush" Value="{x:Static util:ApplicationVariables+Colors.Management}"/>
ApplicationVariables+Colors
语法意味着Colors是ApplicationVariables内部的嵌套类型