Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've an image structured in this way:

<Image Height="32" Width="32" Source="{Binding MatchController.Match.TeamHomeShield}" IsEnabled="False" />

and a label:

<Label Content="{Binding MatchController.Match.TeamHomeShield}" />

my problem's that I can't get the image displayed on the Image, but on the label I can see the value of TeamHomeShield, the property is created in this way:

        private string _teamHomeShield;
        public string TeamHomeShield
        {
            get { return _teamHomeShield; }
            set
            {
                _teamHomeShield = value;
                OnPropertyChanged();
            }
        }

        private string _teamAwayShield;
        public string TeamAwayShield
        {
            get { return _teamAwayShield; }
            set
            {
                _teamAwayShield = value;
                OnPropertyChanged();
            }
        }

why happen this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
207 views
Welcome To Ask or Share your Answers For Others

1 Answer

Please check your Image source format "/YourAssemblyName;component/YourPath/YourImage with extension"

xaml:

<Grid>
    <Image Source="{Binding ImagePath}" Width="200" Height="100"/>
</Grid>

xaml.cs:

 public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = objviewmodel;
        objviewmodel.ImagePath = @"/ImageLoading;component/Assets/Desert.jpg"; // your image path

    }
    viewmodel objviewmodel = new viewmodel();

}


public class viewmodel : INotifyPropertyChanged
{

    #region INotifyPropertyChanged

    public event PropertyChangedEventHandler PropertyChanged;

    public void OnpropertyChanged([CallerMemberName] string PropertyName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
        }
    }

    #endregion


    private string _ImagePath=string.Empty;

    public string ImagePath
    {
        get { return _ImagePath; }
        set { _ImagePath = value; OnpropertyChanged(); }
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...