ger*_*rod 4 c# wpf xaml static
可以说我有两个这样的类:
public class LocalResources
{
public Color ForegroundColor { get; set; }
}
public static class OrganisationModule
{
public static LocalResources Resources = new LocalResources
{
ForegroundColor = Color.FromRgb(32, 32, 32)
};
}
Run Code Online (Sandbox Code Playgroud)
在XAML代码中,为什么我不能这样做(假设存在所有正确的xml命名空间)?
<TextBlock Foreground="{x:Static Modules:OrganisationModule.Resources.ForegroundColor}" />
Run Code Online (Sandbox Code Playgroud)
当我编译时,我收到错误: Cannot find the type 'OrganisationModule.ColorManager'. Note that type names are case sensitive.
这里有两个错误.首先在OrganisationModule类中,您需要提供Resources作为属性.目前它不是属性,您需要编写Get和/或Set
然后对于Binding我们需要以下表达式
Foreground="{Binding Path=ForegroundColor,Source={x:Static Modules:OrganisationModule.Resources}}" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3352 次 |
| 最近记录: |