HyperLinkBut​​ton中的多个绑定导航URI

时间:2012-02-20 12:13:20

标签: c# silverlight windows-phone-7 xaml

我正在尝试为Windows Phone 7.5构建一个应用程序,我有一些文本块,我使用以下代码绑定xml文件中的一些值

<TextBlock Grid.Row="2" TextWrapping="Wrap" Text="{Binding People}" Foreground="White" />

现在我想在链接中绑定一个HyperLink Button 2绑定。所以我可以创建一个facebook分享。

<HyperlinkButton Grid.Row="4" Content="Share" TargetName="_blank" NavigateUri="http://www.facebook.com/sharer.php?u={Binding People}&title={Binding Title}"/>

以上代码不起作用,请指导我使其工作。我已经尝试了一些带有+,“'”和其他东西的炼金术,但似乎没有用。

提前致谢

1 个答案:

答案 0 :(得分:3)

你不能这样做。这不是字符串连接

NavigateUri="http://www.facebook.com/sharer.php?u={Binding People}&title={Binding Title}"

您需要做的是创建converter并将包含PeopleTitle的对象传递给converter。然后在converter内创建URI

像这样的事情。我不确定语法,但你可以得到主要的想法

NavigateUri={Binding Converter={StaticResource YourConverter}, ConverterParameter=''{Binding YourObject}"}

然后在转换器内

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                 YourObject obj = (YourObject) value;
                 //create URI and return it
            }
        }
相关问题