Compiler errors x:Bind-in-ConverterParameter(UWP)编译错误-VS 2017
好的,我基本上有两个Compiler errors x:Bind-in-ConverterParameter(UWP)编译错误-VS 2017,compiler-errors,converter,datatemplate,uwp-xaml,xbind,Compiler Errors,Converter,Datatemplate,Uwp Xaml,Xbind,好的,我基本上有两个ListViews来加载一个集合,然后需要以特定的样式呈现。为此,我使用了一个DataTemplate,如下所示 在这两个DataTemplate中,我需要加载一个图像和一个文本。文本工作正常,但为了返回图像的URL,我必须先获取用户id,然后获取图像哈希,将它们合并在一起并返回URL 因此,我所做的是绑定到用户id,然后使用带有ConverterParameter值x:bind的转换器,将其绑定到图像哈希。我的想法是取这两个值,然后转换器返回最终的字符串。值和参数都是字符串
ListView
s来加载一个集合,然后需要以特定的样式呈现。为此,我使用了一个DataTemplate
,如下所示
在这两个DataTemplate
中,我需要加载一个图像和一个文本。文本工作正常,但为了返回图像的URL
,我必须先获取用户id
,然后获取图像哈希
,将它们合并在一起并返回URL
因此,我所做的是绑定到用户id
,然后使用带有ConverterParameter
值x:bind
的转换器,将其绑定到图像哈希
。我的想法是取这两个值,然后转换器返回最终的字符串。值
和参数
都是字符串
(URI
)
在编译时(不是在运行时),我得到了这个错误
,我可以在任何地方找到答案,我不知道它们是什么意思。事件值不能跨线边界断开
DataTemplate
s如下所示:
xmlns:conv="using:App_Name.Converters"
<conv:IconIdToUrlConverter x:Key="IconIdToUrlConverter"/>
<conv:AvatarIdToUrlConverter x:Key="AvatarIdToUrlConverter"/>
<DataTemplate x:Key="GuildsListDataTemplate" x:DataType="discweb:SocketGuild">
<StackPanel Margin="0,5,0,0">
<Ellipse Width="40" Height="40">
<Ellipse.Fill>
<ImageBrush ImageSource="{x:Bind IconId, Mode=OneWay,Converter={StaticResource IconIdToUrlConverter},ConverterParameter={x:Bind Id,Mode=OneWay}}"/>
</Ellipse.Fill>
</Ellipse>
<TextBlock TextAlignment="Center" TextWrapping="WrapWholeWords" Margin="0,2,0,0" Text="{x:Bind Name, Mode=OneWay}" Foreground="White" FontSize="12" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="GuildUsersListDataTemplate" x:DataType="discweb:SocketGuildUser">
<StackPanel Orientation="Horizontal" Margin="0,0,2,0">
<Ellipse Width="10" Height="10">
<Ellipse.Fill>
<ImageBrush ImageSource="{x:Bind AvatarId, Mode=OneWay,Converter={StaticResource AvatarIdToUrlConverter},ConverterParameter={x:Bind Discriminator,Mode=OneWay}}"/>
</Ellipse.Fill>
</Ellipse>
<TextBlock TextAlignment="Center" TextWrapping="WrapWholeWords" Text="{x:Bind Username,Mode=OneWay}" Foreground="White" FontSize="10" />
</StackPanel>
</DataTemplate>
注意:我使用的是当前最新版本的Visual Studio 2017
!此外,我还观察到,当使用绑定
而不是x:Bind
时,编译器不会给出任何错误,但代码不会执行预期的操作,因为绑定在页面
的数据上下文
中搜索,而不是我在数据模板
中专门定义的
编辑(基于评论):
第33行和第59行是我的DataTemplates中的两个ImageBrush,我已经用它们更新了上面的代码。两个ConverterParameter值都返回int。以下代码包括converters类:
public class AvatarIdToUrlConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
BitmapImage s;
if (value == null || parameter == null)
s = new BitmapImage(new Uri("https://something.com/assets/dd4dbc0016779df1378e7812eabaa04d.png"));
else
s = new BitmapImage(new Uri(String.Format("https://something.com/avatars/" + parameter.ToString() + "/" + value.ToString() + ".png?size=128")));
return s;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
public class IconIdToUrlConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
BitmapImage s;
if (value == null || parameter == null)
s = new BitmapImage(new Uri("https://something.com/assets/dd4dbc0016779df1378e7812eabaa04d.png"));
else
s = new BitmapImage(new Uri(String.Format("https://something.com/icons/" + parameter.ToString() + "/" + value.ToString() + ".png?size=128")));
return s;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
你能提供一个项目吗?至少显示了可能导致问题的转换器。以及ChatView.xaml
上第33行和第59行的代码行是什么?我目前无法在我这边重现您的问题。根据您的评论添加了代码。正如我在最初的帖子中所描述的,第33行和第59行是日食中的两个画笔。非常感谢。你能提供一个项目吗?至少显示了可能导致问题的转换器。以及ChatView.xaml
上第33行和第59行的代码行是什么?我目前无法在我这边重现您的问题。根据您的评论添加了代码。正如我在最初的帖子中所描述的,第33行和第59行是日食中的两个画笔。非常感谢。
public class AvatarIdToUrlConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
BitmapImage s;
if (value == null || parameter == null)
s = new BitmapImage(new Uri("https://something.com/assets/dd4dbc0016779df1378e7812eabaa04d.png"));
else
s = new BitmapImage(new Uri(String.Format("https://something.com/avatars/" + parameter.ToString() + "/" + value.ToString() + ".png?size=128")));
return s;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
public class IconIdToUrlConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
BitmapImage s;
if (value == null || parameter == null)
s = new BitmapImage(new Uri("https://something.com/assets/dd4dbc0016779df1378e7812eabaa04d.png"));
else
s = new BitmapImage(new Uri(String.Format("https://something.com/icons/" + parameter.ToString() + "/" + value.ToString() + ".png?size=128")));
return s;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}