2014-11-04 61 views
0

我正在开发Windows Phone 8.1应用程序。如果我在BitmapIcon控制设置UriSource像:XAML - Dynamics在BitmapIcon中设置UriSource

<BitmapIcon Width="35" Height="35" Margin="0" RequestedTheme="Dark" UriSource="/Assets/Main/Operations/appbar.information.png"> 

一切工作正常,但如果我想将它设置动态我见犹空场。

我正在使用MVVM Light。我的模型看起来像:

... 
    private string _icon; 
    public string Icon 
    { 
     get { return _icon; } 
     set { _icon = value; RaisePropertyChanged("Icon"); } 
    } 
    ... 

接下来我创建对象,添加到列表并在此基础上创建可观察集合。其他领域的正常工作,但不是这样的:

<BitmapIcon Width="25" Height="25" Margin="0" UriSource="{Binding Icon, Mode=TwoWay}"/> 

回答

1

BitmapIcon.UriSourceUristring型。你应该使用这样的:

private Uri _icon; 
public Uri Icon 
{ 
    get { return _icon; } 
    set { _icon = value; RaisePropertyChanged("Icon"); } 
} 

然后在您的视图模型,你会这样设置图标:

Icon = new Uri("ms-appx:///Assets/Main/Operations/appbar.information.png"); 

This answer解释了为何使用在XAML字符串的作品,但不是在C#代码。