Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

c# - Image Source Binding not display anything

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

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

1 Reply

0 votes
by (71.8m points)

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(); }
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...