0

In my Silverlight5 application that using mvvm, need to acheive the below one. I have the image folder that contains images. How to get the whole image path and assign it to the hyperlinkbutton.

<HyperlinkButton Content="Preview"  NavigateUri="{Binding image_value}"
                                                          TargetName="_blank" />

but i need to give the path like the following one ,

 ("./Images/{0}", String_Value)

Help me to achieve this..

4

2 回答 2

2

您应该使用Converterwhich 将附加这些字符串:

public class ImagePathConverter : IValueConverter
{             
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parametr, CultureInfo culture)
    {
        var imgPath = "./Images/{0}";
        return string.Format(imgPath, value);
    }

    public object ConvertBack(object value, Type targetType, object parametr, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion

}

并且xaml

<Page.Resources>
   <converters:ImagePathConverter x:Key="imagePathConverter"/>
   ...
</Page.Resources>   

   ...

<HyperlinkButton Content="Preview"  NavigateUri="{Binding image_value, Converter={StaticResource imagePathConverter}}" TargetName="_blank" />

*我建议不要对路径进行硬编码,而是将其放入资源文件中,这将提供更大的灵活性。

于 2012-11-01T14:46:20.613 回答
0

海我找到了解决方案..

 <HyperlinkButton Content="Preview" Margin="2"  NavigateUri="{Binding String_Value,StringFormat='http://localhost:23411/ClientBin/Images/{0}'}" VerticalAlignment="Center" TargetName="_blank" />

我把它放在我的代码中,它运行良好..

于 2012-11-02T05:59:48.227 回答