I'm trying to set an image source in XAML but keep getting "Could not find part of a path..." (plus the directory I want to call). I think I'm messing up what location I'm supposed to be calling. The hierarchy looks something like:
-Solution
-Project
-Data
-Images
-Image_I_want_to_use.png (placeholder name)
-Themes
-Demo
-Default
-fileImWorkingIn.xaml
-other files
-other folders
-Another Project
-Third Project
How would I configure my image source in XAML so the file I'm working in can utilize the image(s)?
I tried
<Image Source="/Project;component/Images/image_to_use.png">
(where each name is simply a placeholder) but had no luck. Any pointers? Apologies if this is trivial.
Thanks!
In .NET 4, this Image.Source value would work:
<Image Source="/AssemblyName;component/FolderName/image_to_use.png">
However, Microsoft made some horrible changes in .NET 4.5 that broke many different things and so in .NET 4.5, you'd need to use the full pack path like this:
<Image Source="pack://application:,,,/AssemblyName;component/Images/image_to_use.png">
What fixed it:
<Image Source ="pack://application:,,,/Images/image_name.png"></Image>
I also changed the Build Action to content.
Thanks for your help everyone!
Related
I've used source_group dozens of times with C++ Projects to organize my files, yet for C# Projects this does not seem to work:
set (FOO myfoo.cs)
set (BAR mybar.cs)
set (FILES
App.xaml
App.xaml.cs
MainWindow.xaml
MainWindow.xaml.cs
)
set (PROPERTIES <property files here>)
add_executable(
${CMAKE_PROJECT_NAME}
App.config
${FILES}
${FOO}
${BAR}
${PROPERTIES}
)
source_group(Models FILES ${FOO})
source_group(ViewModels FILES ${BAR})
Do folders not work for C# Projects via CMake? Or what am I doing wrong?
EDIT: Forgot to mention, in my main CMakeLists.txt file I already have:
if (WIN32)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
endif (WIN32)
I then call add_subdirectory where the above CMakeLists.txt is. This setup seems to work okay for my other C++ project that is added in the same way.
You can use the VS_CSHARP_Link property to set how a file is viewed in a C# project. (Don't ask for documentation; I can't find any. I learned about this setting by perusing the source code. Looks like it first appeared in version 3.18.)
For example, after adding ${SOME_ROOT_DIR}/some/path/to/someFile.cs to your project's sources, control how it's organized with:
set_source_files_properties("${SOME_ROOT_DIR}/some/path/to/someFile.cs"
PROPERTIES VS_CSHARP_Link "My own folder\someFile.cs")
It seems that in C# Projects, source_group is not honored. However, folders are still possible simply by giving it a directory structure in the list, like so:
set(MODELS
Models/CompileOptionsModel.cs
)
set(VIEWMODELS
ViewModels/CompileOptionsViewModel.cs
)
set(PROPERTIES
...
)
set(Files
...
)
add_executable(
${APPNAME}
App.config
${MODELS}
${VIEWMODELS}
${FILES}
${PROPERTIES}
)
This will result in folders Models and ViewModels appearing.
I'm trying to localize my app, I've created several Resources.[culture].resx but program ignores them all and always loads default Resources.resx.
I have this code in App construtor (and in OnStartup event)
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
My resources are called Resources.en-US.resx, Resources.cs-CZ.resx and Resources.resx
Code in WPF is
xmlns:p="clr-namespace:WpfThermalLabelEditorApp.Properties"
Title="{x:Static p:Resources.Title}"
This should load en-US localization but it doesn't. Loads default. I tried to delete AssemblyInfo and even putting <UICulture> tags into csproj
Not sure if this is the answer, but FWIW: I always set both CurrentCulture and CurrentUICulture like so;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(languageAbbreviation);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageAbbreviation);
And be sure to double check the abbreviation you use is the same for all references. That should fix your problem.
EDIT1: Make sure your resource files are set to public, the access modifier should be somewhere near the top when you're viewing the resource file. Double check this says public and rebuild. Also, to call your resource file key do so like this:
<TextBlock xmlns:local="clr-namespace:WpfApplication2" Text="{x:Static local:Resource1.myname}"/>
Where...
"WpfApplication2" is replaced with your project name
"Resource1" is replace with the name of your resource file (without culture id, e.g. for your case it would just be Resources)
"myname" is replaced with the key you want
I came across the same problem, the solution was to clean and rebuild the project. No need to create new project.
Well, after 2 days I've solved my problem. My solution was correct. I have no idea what was wrong but I've created a new project, moved all my data to a new one and suddenly everything worked as a charm.
Here is a few usefull links:
WPF localization and globalization
Localization tutorial
Localization tutorial 2
I updated my xamarin ios-project to the unified API (64 Bit support). Everything worked as expected. The project builds and works.
But I detected one problem. The binding to UILabel.Text properties won't work anymore. All other bindings are still working (to a UIButton.Hidden property for example). Here is my code:
// Create bindings
var set = this.CreateBindingSet<MyView, MyViewModel>();
set.Bind(labelitem) // not working
.For(t => t.Text)
.To(v => v.MyStringValue);
set.Bind(buttonitem) // working
.For(b => b.Hidden)
.To(v => v.MyboolValue)
.WithConversion(new InverseBoolValueConverter());
set.Apply();
I'm using MvvmCross for the bindings. Bevore the unified-update everything worked fine.
First I tried to change the Linker-Option to "don't link". Same problem.
Can anyone explain me, what's happen? Thanks
Edit
I found a info in the output while debugging my project:
Weak Target is null in MvxUILabelTextTargetBinding - skipping set
There are some issues that some people are seeing, others are not, with the new GC in the latest Xamarin "stable" releases (maybe differences between VS and XS - it's not clear...). You can read about these on https://github.com/MvvmCross/MvvmCross/issues/902 (with some background on Migrating to Unified API and new reference counting)
There's an attempt to address these in http://slodge.blogspot.co.uk/2015/02/351-alpha-release.html - please do try the alpha packages to see if they help.
If not, then the only accepted workaround right now is to promote your UILabel to a private variable in your View.
I'm writing a library of WPF user controls and am having trouble with a resource image that I'm trying to access via some XAML. Just for fun, the image displays as expected at design time and only fails at run time.
I've tried setting the build action to "none", "content", "resource" and "embedded resource", but I keep getting the following cryptic exception:
'Provide value on
'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an
exception.' Line number '18' and line position '6'.
Looking at the inner exception, it seems to be a problem with the pack URI. When I try:
<ImageBrush x:Key="mybrush" ImageSource="pack://application:,,,/Resources/an image.png" />
I get:
Assembly.GetEntryAssembly() returns null.
OK, so this is probably because my library is now being called from within another assembly. But when I follow the recommendations and try:
<ImageBrush x:Key="mybrush" ImageSource="pack://application:,,,my_assembly;component;/Resources/an image.png" />
I get an inner exception of:
"The URI prefix is not recognized."
To add to the fun, I have another image resource which I have no problem accessing via actual C# code (i.e. not through XAML).
What am I doing wrong? Feel like it will be really simple, but am head-desking at the moment.
Change ImageSource to
ImageSource="pack://application:,,,/my_assembly;component/Resources/your_image.png"
I am having a problem using Visual Studio data driven testing. I have tried to deconstruct this to the simplest example.
I am using Visual Studio 2012. I create a new unit test project.
I am referencing system data.
My code looks like this:
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[DeploymentItem(#"OrderService.csv")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "OrderService.csv", "OrderService#csv", DataAccessMethod.Sequential)]
[TestMethod]
public void TestMethod1()
{
try
{
Debug.WriteLine(TestContext.DataRow["ID"]);
}
catch (Exception ex)
{
Assert.Fail();
}
}
public TestContext TestContext { get; set; }
}
}
I have a very small csv file that I have set the Build Options to to 'Content' and 'Copy Always'. I have added a .testsettings file to the solution, and set enable deployment, and added the csv file.
I have tried this with and without |DataDirectory|, and with/without a full path specified (the same path that I get with Environment.CurrentDirectory). I've tried variations of "../" and "../../" just in case. Right now the csv is at the project root level, same as the .cs test code file.
I have tried variations with xml as well as csv.
TestContext is not null, but DataRow always is.
I have not gotten this to work despite a lot of fiddling with it. I'm not sure what I'm doing wrong.
Does mstest create a log anywhere that would tell me if it is failing to find the csv file, or what specific error might be causing DataRow to fail to populate?
I have tried the following csv files:
ID
1
2
3
4
and
ID, Whatever
1,0
2,1
3,2
4,3
So far, no dice.
I am using ReSharper, could it be interfering in some way?
Updated
I have it mostly working now! I am able to use XML, but when I use CSV my column, which is named ID comes back as ID
Not sure why. I've checked the actual file of course, and no weird characters are present.
For anyone having a similar problem, I turned off Just My Code and enabled Net Framework source stepping, etc. so that I could get more detailed debug information. This allowed me to determine that ReSharper was causing me problems. I disabled resharper and modified my attributes like this:
[DeploymentItem("UnitTestProject1\\OrderService.csv")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\bin\\Debug\\OrderService.csv", "OrderService#csv", DataAccessMethod.Sequential)]
And it worked (except as noted). I am still suspicious of the "bin\debug" in my path, but I'm just happy my DataRow is no longer null.
Thanks!
Any ideas?
I was struggling with a similar problem today when trying to make data-driven tests work with CSV input file. The name of the first column had some garbage at the beggining of it, i.e. ID instead of just ID.
It turned out it was an encoding issue. The CSV file was saved in UTF-8 which adds a byte order mark at the beginning, obviously confusing the parser. Once I saved the file in ANSI encoding, it worked as expected.
I know it's an old question, but this information might help someone else ending up on this page.
Have you tried adding it through the properties window?
Go to Test menu -> Windows -> Test View -> the tests will load up.
Click on the test to alter i.e. TestMethod1 and press F4 (properties).
Look for 'Data Source' and click the ellipses next to it
It will walk you through a wizard that sets up the attributes properly for the TestMethod
You have the deployment part set up properly, which is normally the big stumbling block.
You also don't have to set the build action to Copy Always as the deployment does this for you. This option is used if you include items like .xml files you use for configs, or icons/images as part of your project.
Update 1:
Also try this tutorial on MSDN.
Update 2:
Try this post, involving ProcMon
I see that you said you tried putting the CSV itself into the testsettings file, but have you tried just putting in the directory?
<Deployment>
<DeploymentItem filename="Test\Data\" />
</Deployment>
Then your DataSource line will look something like this:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\YOURCSV.csv", "YOURCSV#csv", DataAccessMethod.Sequential)]
If you do it this way, you don't need to specify the DeploymentItem line.
Our folder structure looks like this: Trunk\Test\Test\Data
We include: Test\Data in the deployment
We then access Test\Data via the |DataDirectory|\
All CSVs live within the \Data folder