对于Xamarin.Forms - XAML文件:
是否有一种方法可以将标签的Text属性(在XAML中)绑定到Binding + DynamicResource?可以使用字符串格式吗?
例如,我尝试了这样的内容:
是否有一种方法可以将标签的Text属性(在XAML中)绑定到Binding + DynamicResource?可以使用字符串格式吗?
例如,我尝试了这样的内容:
http://intellitect.com/multibinding-in-xamarin-forms/
这里有一个更简单的实现,可以直接使用:https://gist.github.com/Keboo/0d6e42028ea9e4256715
一个关于这个主题的讨论:https://forums.xamarin.com/discussion/21034/multibinding-support
我认为你需要的是MultiBinding。
尝试创建一个像这样的转换器类:
public class MultiBindingConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return values[0].ToString() + " " + values[1].ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
在你的App.xaml或其他资源字典中引用它
<local:MultiBindingConverter x:Key="MultiBindingConverter" />
然后在你的视图中做类似这样的事情:
<Label>
<Label.Content>
<MultiBinding Converter="{StaticResource MultiBindingConverter}">
<Binding Path="FirstProperty" />
<Binding Path="SecondProperty" />
</MultiBinding>
</Label.Content>
</Label>
FirstProperty和SecondProperty只是ViewModel中的普通属性。
IValueConverter
)的工作... - Milen