我有一个数据列表,其中包含代码、名称和其他一些数据的国家/地区。
List<Country> countries = <deserialized objects from file>
Run Code Online (Sandbox Code Playgroud)
由这样的对象组成:
public class Country
{
public string Code { get; set;}
public string Name { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
用作 DataContext 的对象可能如下所示:
public class Address
{
public string StreetName{ get; set;}
public string CountryCode { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的 XAML 中,我想做这样的事情来显示国家/地区的名称
<TextBlock Text="{Binding Path=CountryCode, Converter={StaticResource CountryNameLookupConverter}}"/>
Run Code Online (Sandbox Code Playgroud)
但是如何让 CountryNameLookupConverter 使用我从 xml 文件中读取的国家/地区列表?