我无法找到正确的语法来直接绑定xaml中列表的项目。
<Listview ItemsSource={Binding Items}>
<Listview.ItemTemplate>
<CustomUserControl Item={Binding} />
</Listview.ItemTempalte>
</Listview>
此代码工作正常。但是当我想在绑定中添加转换器时,它会显示语法错误:
<Listview ItemsSource={Binding Items}>
<Listview.ItemTemplate>
<CustomUserControl Item={Binding ,Converter={StaticResource myConverter}} />
</Listview.ItemTempalte>
</Listview>
有谁知道这样做的方法?
谢谢!
答案 0 :(得分:2)
好的答案就是
var bd = d.getDay();// get day from today's date which be between 0-6 (0 is Sunday and 6 is Saturday
if (bd < 2) {
if (bd == 0) {
bd = 2;
} else {
bd = 3;
}
} else {
bd = 1;
}
//variable lbd will get the last business day by reducing the calculated lbd from today's date
var lbd = (d.getMonth() + 1) + "/" + (d.getDate() - bd) + "/" + d.getFullYear();
没有逗号..
答案 1 :(得分:0)
我认为你以错误的方式使用转换器。您可以尝试将转换器定义为静态资源。
<converters:MyConverter x:Key="myConverter" />
并以这种方式使用
<Listview ItemsSource={Binding Items}>
<Listview.ItemTemplate>
<CustomUserControl Item="{Binding, Converter={StaticResource myConverter}" />
</Listview.ItemTempalte>
或
<Listview ItemsSource={Binding Items}>
<Listview.ItemTemplate>
<CustomUserControl Item="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource myConverter}" />
</Listview.ItemTempalte>