【问题标题】:Multiple Bind in HyperLinkButton Navigate URIHyperLinkBut​​ton Navigate URI 中的多重绑定
【发布时间】:2012-02-20 20:26:41
【问题描述】:

我正在尝试为 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}"/>

上面的代码不起作用,请指导我使它起作用。我已经用 +,"'" 和其他东西尝试了一些炼金术,但似乎不起作用。

提前致谢

【问题讨论】:

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


    【解决方案1】:

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

    NavigateUri="http://www.facebook.com/sharer.php?u={Binding People}&amp;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
                }
            }
    

    【讨论】:

    • 对于像我这样的新手(新知识)来说,这是一个地狱般的工作,我会试试的。感谢您的提示。
    猜你喜欢
    • 2012-07-19
    • 2015-03-29
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多