【发布时间】:2015-05-04 15:44:21
【问题描述】:
我见过一些类似的问题,但没有一个对我来说足够简单。我已经用 C# 编码大约两个星期,使用 WPF 大约两天。
我有课
namespace STUFF
{
public static class Globals
{
public static string[] Things= new string[]
{
"First Thing"
};
}
}
还有一扇窗户
<Window
x:Class="STUFF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:STUFF"
Title="STUFF"
Height="600"
Width="600">
<Window.Resources>
<local:Globals x:Key="globals"/>
</Window.Resources>
<Grid>
<Label Content="{Binding globals, Path=Things[0]}"/>
</Grid>
从 XAML 内部将代码中的数据绑定到 XAML 的最简单最简单的方法是什么?
这编译和运行良好,但标签是空白的原因,显然我敢肯定,这回避了我。
【问题讨论】:
-
这并不是真正的代码背后。隐藏代码定义为在 Window1.xaml.cs 文件中找到的代码。每个 .xaml 文件都有一个 .xaml.cs 代码隐藏文件。
-
Window1后面的代码是Window1类中定义的代码?
-
是的,Window1.xaml.cs 是 Window1.xaml 背后的代码。