WPF窗口样式绑定到非静态类的静态属性

问题描述 投票:0回答:1

我正在尝试将边框笔刷颜色绑定到实用程序文件的管理属性。引用非静态类中的静态类的静态属性的语法是什么?

<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);
        }
    }
}
wpf static bind
1个回答
0
投票

您不需要任何类的实例即可访问static成员。

Colors属性似乎也没有改变,因此可以使用Binding扩展名代替{x:Static}

<Setter Property="BorderBrush" Value="{x:Static util:ApplicationVariables+Colors.Management}"/>

ApplicationVariables+Colors语法意味着Colors是ApplicationVariables内部的嵌套类型

© www.soinside.com 2019 - 2024. All rights reserved.