Fuente de imagen de enlace WPF
tal vez una pregunta estúpida, pero ya no lo sé ...
Tengo la clase ViewModel como esta:
public class MainWindowsViewModel : INotifyPropertyChanged
{
private ImageSource _img;
public ImageSource StatusImage
{
get { return _img; }
set
{
_img = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName]String propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
El enlace en XAML se ve así:
<Window.DataContext>
<VM:MainWindowsViewModel />
</Window.DataContext>
<Image x:Name="gui_image_status" HorizontalAlignment="Left" Height="26" Margin="144,10,0,0" VerticalAlignment="Top" Width="29" Source="{Binding Path=StatusImage}" />
Y configuro el contenido de ImageSource así:
MainWindowsViewModel _view = new MainWindowsViewModel();
var yourImage = new BitmapImage(new Uri(String.Format("Sources/{0}.png", "red"), UriKind.Relative));
_view.StatusImage = yourImage;
Pero no funciona. Creo que ese problema está en esoNotifyPropertyChanged
, porque intenté colocar el punto de freno en elset
yget
. Get
se activó algunas veces al inicio, después de esoset
activado también con ImageSource correcto, pero después de esoget
no se activó más. Como si nunca hubiera pasado nada.
Realmente es simplemente vinculante lo que he hecho muchas veces de manera similar ... No sé por qué no funciona esta vez.