Visual Studio Extension Image is good in design mode but it is hidden in runtime [duplicate] - visual-studio-extensions

This question already has answers here:
WPF - Import image as resource
(3 answers)
Closed 4 years ago.
I am creating a Visual Studio extension with a Custom Tool Window (wpf window).
I have a menu:
<MenuItem Header="_Function" Name="mn" >
<MenuItem Name="menuSearch" Click="MenuSearch_Click" Header="Search">
<MenuItem.Icon>
<Image Source="Resources/search.jpg" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Edit" Name="menuSave" Click="MenuSave_Click" >
<MenuItem.Icon>
<Image Source="Resources/pen.jpg" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
Both of the icons are good in design mode:
But when I run the project only the first one is working:
I have read this post: Image not visible in WPF 2015
and both of the images are Build Action: Resource. And the last thing i must say is that the second image works if I set a static url:
<MenuItem.Icon>
<Image Source="J:\My_Programs\1397\MyKeywords\MyKeywords\Resources\pen.jpg" />
</MenuItem.Icon>
Do you know the solution? Thanks.
Update
And this post:
WPF - Import image as resource
will not help because one image is working and another not, in a same condition.

It seems that in a VSIX project, Some of the changes do not affect until the visual studio restart. I restarted the visual studio and now every things are OK with:
Build Action: Resource
Copy To Output Directory: Do Not Copy

Related

After updating Next js from 11 to 13 version, images from assets folder stopped working

I've updated NextJs in my application and huge part of images stopped working.
I keep my images in asstes folder and after running a project usually all of them are transferred to .next folder, but now only a small part.
My flow:
...
import RightLogo from '#/images/about/right_logo.png';
export default function AccountSettingLayout({ children }) {
return (
<Layout title='Account Setting'>
<div className={styles.accountSettingLayout}>
<div className={styles.right_logo}>
<Image src={RightLogo} alt='Right logo' />
...
The path to the image is correct, but but on the site we just have an alt text.
Source in browser
Network in browser
assets folder
I've found a solution, but it's a bit dummy. If I'll keep all the images in public folder, and will indicate the path to the image as here:
`
<Image
src="/about/right_logo.png"
alt='Right logo'
width={200}
height={500}
/>
Could you suggest something?

Xamarin Forms: Exactly how specify local filename for iOS WebView WebViewSource

I have a Xamarin Forms Webview that is successfully displaying a local "hard-coded" file on Android and UWP, but I can't get it to work on iOS. I have done the usual searches: there is help out there for Web URL's and for HTML embedded in the C# code, but I cannot find anything that solves my problem: exactly how do I specify the filename and where do I put the HTML files?
I have pasted the XAML below. I have the GettingStartedWizardWebPage folder both (temporarily, until I figure out what works) in the main iOS project folder and also under iOS Resources. I have tried specifying the file name both with and without a preceding ///. Is there some other prefix I should be using, like file: for Android or ms-appx-web: for UWP? I have the HTML files with BuildAction BundleResource and I have tried all of the Copy variations (but there are a lot of combinations of name prefix, Copy options and file location and I have probably not tried every combination).
Specifically, I have read https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows#local-html-content and followed the directions there to the best of my ability. For Android I coded Value="file:///folder/page" and it works. For UWP I coded Value="ms-appx-web:///folder/page" and it works. What do I code for Value= for iOS? What is the "base URL"? Is the tutorial trying to say that I need code to determine the Base URL?
It doesn't crash or give any errors; it just displays a blank window. The second row of the grid shows up and displays where I would expect it to be.
I have read the discussions of UIWebView and WKWebView but I don't get what exactly I should be doing. AFAIK I would be willing to use either.
VS 2022 Community 17.4.0 Preview on Windows 64 Pro, with both Cloud iPhone 13 Simulator and real iPhone 5.
<Grid RowDefinitions="*,AUTO" Margin="6, 6, 6, 6" x:Name="MainContent">
<WebView WidthRequest="1000" HeightRequest="1000" Grid.Row="0" >
<WebView.Source>
<OnPlatform x:TypeArguments="WebViewSource">
<OnPlatform.Platforms>
<On Platform="Android" Value="file:///android_asset/GettingStartedWizardWebPage/WebPage.html" />
<On Platform="UWP" Value="ms-appx-web:///GettingStartedWizardWebPage/WebPage.html" />
<On Platform="iOS" Value="///GettingStartedWizardWebPage/WebPage.html" />
</OnPlatform.Platforms>
</OnPlatform>
</WebView.Source>
</WebView>
...
Okay. I solved this. The linked tutorial is less than forthcoming on one point, and wrong on the details of others.
I. You just cannot do this for iOS in XAML. For UWP and Android there is a fixed, short "prefix" (base URL) that goes on the front of the filename as discussed in the article and as shown in my XAML above. For iOS it is a 100-or-so character string that is very application and device dependent, so you can't hard-code it in the XAML. You have to use C# code with a dependency routine -- as shown in the tutorial, but not emphasized as explicitly as I just did.
II. The prefixes shown in the tutorial are wrong, or at least won't work correctly in device-independent code. NSBundle.MainBundle.BundlePath on iOS returns a pathname without a terminating slash, so (a.) you want a leading slash on the hard-coded "low-order" part of your filename; and (b.) therefore the Android routine wants to return "file:///android_asset" (without the trailing slash shown in the tutorial) and the UWP routine wants to return "ms-appx-web://" with two trailing slashes, not the three shown in the tutorial -- which seems odd, but your hard-coded slash will make for three total.
III. Contrary to what the tutorial says, you do NOT have to read the file yourself and then deal with special considerations so that the HTML page can access linked objects. Just put BaseUrl + "Your hard-coded filename starting with a slash" into WebView.Source and WebView will read the file (on all three platforms) including any linked images and so forth.
IV. Put the HTML pages in the main iOS application folder, not under Resources. That is the path that NSBundle.MainBundle.BundlePath returns.

Image added to Xamarin Forms not displaying

I'm trying to build a very simple Xamarin Forms app. Essentially, it just displays an image of a form. The image is part of the project (in the Assets folder). However, I'm struggling to work out exactly what I need to do to get it to display the image.
Here's the Xaml:
<Image Grid.Column="2" Grid.Row="0" Grid.RowSpan="3"
BackgroundColor="Aqua" Aspect="Fill" Source="../Assets/tmp.png"/>
I've tried various combinations of path (./Assets/tmp.png for example), I've even tried copying the image to the Assets folder in the UWP app that I'm trying to run, but I can't get the image to display.

Xamarin.Forms embedded image not showing

There are several posts here on stackoverflow that cover this, but none are the cause. I've tried several sources including the documentation and I can not get this to work.
I'm following a tutorial by mosh on Udemy and he's showing how to use an embedded resource file.
I am working with Visual Studio 2017.
I've added a folder in the HelloWorld folder called images and placed an image called background.jpg in it.
When you right click the image and set the Build Action to EmbeddedReesource you're supposed to get a Resource Id. None is there, not even the box shows up. I'm thinking that's a new feature that was removed.
I found out the resource path is HelloWorld.images.background.jpg.
My xaml is like this:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HelloWorld.ImagePage"
BackgroundColor="Black">
<ContentPage.Content>
<Image x:Name="image" Aspect="AspectFill" />
</ContentPage.Content>
</ContentPage>
Next, my c# code is like this:
public ImagePage ()
{
InitializeComponent ();
image.Source = ImageSource.FromResource("HelloWorld.images.background.jpg");
}
And I've tried placing the image in the android project under Resources/Drawable, but doesn't that defeat the purpose?
Any help would be great. Thanks ahead of time.
Here is my VS Solution Explorer:
This way of embedding images is still supported. Check out this page in the documentation on how to do it. These are the basic steps:
Set Build Action of the file to EmbeddedResource, you can do this in the properties of the file
Refer to the image from your PCL with a dot delimited identifier. The filename is build up like this: AssemblyName.Folder.ImageName.ext
If your image is not in a folder, you can leave is out, if it is in multiple folders, add each one separated with a dot. An example could look like this:
var embeddedImage = new Image { Aspect = Aspect.AspectFit };
embeddedImage.Source = ImageSource.FromResource("WorkingWithImages.beach.jpg");
Here the assembly (probably your project name for your PCL) is named 'WorkingWithImages' and the file is not in a folder, the file is named 'beach.jpg'. In the case of Android I think you should also mind that you do not put in hyphens or any other characters than numeric, alphabetic and underscores.
That being said, you also say:
And I've tried placing the image in the android project under
Resources/Drawable, but doesn't that defeat the purpose?
I'm not entirely sure what you mean here, but I took it that you think it defeats the purpose of a multi-platform app from a single code-base. I must disagree with you there. Although I see how you could think that, working with images is something that is very platform specific. All platforms have a very different way of showing and scaling images and it would be nearly impossible to reconcile all that for Xamarin. Having the images in the PCL like you want to do now, will completely disable the whole scaling mechanism in place and suddenly you are responsible for making it look good on all kinds of devices, resolutions and form factors. That is why I always have the images resources per platform project.

Why would scenebuilder 2.0 fail to open my fxml file?

I have an fxml file that I created using SceneBuilder 2.0. This file is used in my JavaFx project that I am developing using Netbeans 8. Today, SceneBuilder stopped working with my file. When I tried to open it, SceneBuilder would minimize and would not open the file. I don't have any custom components in my scene graph.
I copied the contents of the file into a new fxml file and gave it a new name. SceneBuilder was then able to open this file even though the contents are identical to the file that it is unable to open.
What is going on here?
my apologies, but I am unable to post the contents of the fxml file.
Okay.. so here I am searching for the solution for this weird problem! Seeing none of the other answers working for me, I did the random most thing I could think of and it worked.
Open SceneBuilder (a brand new one). Go to File > Open Recent > Clear Menu. Close Scene Builder.
Now the bug should be fixed (it did for me)
PS: I am ashamed of posting this answer. But since this is a nasty bug which wasted time, I don't want anyone else to waste theirs'.
PPS: Also, I can't double-check this solution, since it worked for me and I can't recreate the buggy scenario anymore.
I solved this problem by alt-tabbing to the SB program, then maximizing the window (shortcut: window key + up arrow key).
Seems to be a SB bug.
I had the same problem. looks like it is a bug.
I have solved it by Creating a new FXML file (Empty) and copied all the code of original FXML file to it . The new FXML opened by SceneBuilder.
Also had this issue with Win 7. Trick is to right click the SB task bar icon, maximize the window, drag it down by the title bar and a real tiny window should show up, re-size the window and that should do it. I think it's an SB display bug. Good luck.
For me the problem was with the path of the image i was giving in the FXML file.
i was able to solve the issue by using # followed by image path.
With this syntax error you will be able to run your application, but the scene builder will refuse to open the file.
for eg(assuming that you are providing relative path):
Wrong syntax:
<ImageView fitHeight="31.0" fitWidth="40.0" pickOnBounds="true" preserveRatio="true" >
<image>
<Image url="img/image.png"></Image>
</image>
</ImageView>
Correct syntax:
<ImageView fitHeight="31.0" fitWidth="40.0" pickOnBounds="true" preserveRatio="true" >
<image>
<Image url="#/img/1000px-evobus.svg1.png"></Image>
</image>
</ImageView>
Spent about 4 hours and this is how I solved it. In my FXML document, I had a FlowPane with a </child> tag. I changed it to <child></child> and it worked. SceneBuilder opened the FXML document. I know this is silly, and I can't explain why this happens, but I can reproduce it.
In NetBeans go to Tools; Options;Java; JavaFX and set the path to the Scene Builder Home. That should fix the problem

Resources