我应该使用哪个命名空间和程序集在 Xamarin 中的共享项目中声明转换器。
对于该资源
<TabbedPage.Resources>
<ResourceDictionary>
<local:WidthConverter x:Key="widthConverter"/>
</ResourceDictionary>
</TabbedPage.Resources>
如果我选择 windowsPhone 作为启动项目,则此声明有效:
xmlns:local="clr-namespace:LeMagXam;assembly=LeMagXam.WinPhone"
如果我选择 Android 作为启动项目,则此声明有效:
xmlns:local="clr-namespace:LeMagXam;assembly=LeMagXam.Android"
现在我应该用什么来使它适用于 MixedPlateform,我尝试了这个但没有成功:
xmlns:local="clr-namespace:LeMagXam;assembly=LeMagXam"
先感谢您。
编辑有我的完整代码以便更好地理解
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LeMagXam.View.HomePage"
xmlns:local="clr-namespace:LeMagXam;assembly=LeMagXam"
Title="LeMag"
BackgroundImage="bg_light.png"
ItemsSource="{Binding CategoriesList}"
>
<TabbedPage.Resources>
<ResourceDictionary>
<local:WidthConverter x:Key="widthConverter"/>
</ResourceDictionary>
</TabbedPage.Resources>
<TabbedPage.ItemTemplate>
<DataTemplate>
<ContentPage Title="{Binding Name}">
<-- ... -->
<Image Source="{Binding Category.ImageArticleTitle.Source}" HorizontalOptions="Start"
WidthRequest="{Binding , Converter={StaticResource widthConverter},
ConverterParameter=150}"
<-- ... -->
</ContentPage>
</DataTemplate>
</TabbedPage.ItemTemplate>
</TabbedPage>
宽度转换器.cs
namespace LeMagXam
{
public class WidthConverter : IValueConverter
{
#region IValueConverter implementation
public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (double)parameter * App.RatioWidth;
}
public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException ();
}
#endregion
}
}