Reputation: 776
Not able to set image source Uri on find Object. Stackpanel contain two children Textbox and image control.
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
var textBox = (TextBox)sender;
textBox.Style = Application.Current.Resources["TextBoxNormal"] as Style;
textBox.FontSize = 15;
textBox.Foreground = new SolidColorBrush(Colors.Gray);
var stackpanel = textBox.Parent as StackPanel;
if (stackpanel == null)return;
var img = stackpanel.Children.Where(a => a is Image).FirstOrDefault();
if (textBox.Text != "")
{
//I was trying set Uri as mention below, but there is Nothing like "Image.Source"
//image.Source = new BitmapImage(new Uri("/Images/Others/TickRight.png", UriKind.RelativeOrAbsolute));
}
Upvotes: 1
Views: 216
Reputation: 776
You need cast img as Image
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
var stackpanel = textBox.Parent as StackPanel;
if (stackpanel == null)return;
var img = stackpanel.Children.Where(a => a is Image).FirstOrDefault() as Image;
}
Upvotes: 1
Reputation: 2033
So I Would suggest Trouble shooting here.
if (textBox.Text != "")
{
BitmapImage picture = new BitmapImage(new Uri("/Images/Others/TickRight.png", UriKind.RelativeOrAbsolute));
picture.ImageFailed += (o, e) => System.Threading.SynchronizationContext.Current.Send((oo) => System.Windows.Browser.HtmlPage.Window.Alert("Image failed: " + e.ErrorException), null);
picture.ImageOpened += (o, e) => System.Threading.SynchronizationContext.Current.Send((oo) => System.Windows.Browser.HtmlPage.Window.Alert("Image opened: " + e.OriginalSource), null);
image.Source = picture;
}
//BANG.. your error should be naked!
Upvotes: 1