This question already has answers here:
Load a ResourceDictionary from an assembly
(3 answers)
Closed 8 years ago.
I'm having some issues. I want my app to load a ResourceDictonnary dynamically in app.xaml.cs.
This is my code for the moment :
ResourceDictionary theme = XamlReader.Load(???);
Resources.MergedDictionaries.Add(theme);
The problem is, how can I get my ResourceDictionnary stream from the xaml file ? I don't want to copy the xaml file with the exe. It's build action is set to Page and I want to load it.
Can you tell me how to do that ?
Thanks !
try using the following code (I call it from my IModule.Initialize)
Application.Current.Resources.MergedDictionaries
.Add(new ResourceDictionary
{
Source = new Uri(#"pack://application:,,,/My.Application;component/Resources/Resources.xaml")
});
see the project tree in attached image:
Related
This question already has answers here:
WPF - Import image as resource
(3 answers)
How do I change an image source dynamically from code-behind in WPF with an image in Properties.Resources?
(1 answer)
Closed 3 years ago.
I would like to use path to image from program resources instead of using full path from windows.
tlo.Fill = new ImageBrush
{
ImageSource = new BitmapImage(new Uri(#"D:\Willie\Documents\ColorTester\ColorTester\Resources\1.jpg", UriKind.Absolute))
};
I want to use path like this:
ImageSource = new BitmapImage(new Uri("ColorTester.Resources.1.jpg"));
Can anyone help me with this, because when I try to use it, visual studio throws and exception "System.UriFormatException"?
I don't know the correct path to your image, if you have a folder named Resources under your project and images are in there, you can address them like below:
ImageSource = new BitmapImage(new Uri("/Resources/1.jpg", UriKind.Relative));
If the image is inside a UserControl and you want to use it in another project, then address it like:
ImageSource = new BitmapImage(new Uri("pack://application:,,,/{YourAssemblyWhereResourceIsLocated};component/Resources/1.jpg"));
Useful links:
WPF image resources
Adding resource dictionaries to a usercontrol library in wpf
https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/pack-uris-in-wpf
This question already has answers here:
In my WPF application, my loaded PNG logo in image shows at design time but not at run time
(4 answers)
Closed 7 years ago.
How to use resource image in WPF image source.I given like below,
<Image Source="pack://siteoforigin:,,,/Resources/008.jpg"/>.
But it displays in edit page.If i run the application it not displaying in the window.
Please help me to solve this.
Thanks.
you need to provide the correct URI to the resource, and the URI depends on the method you used to add the resource this post give the details you need
How to Embed resources
You can add your image to your project Properties.Resources.Images and then use them like that:
<Image Source="{x:Static Properties:Resources.YourImageName}"/>
EDIT >>>>
I've forgotten to say that you have to add this line at the top:
<xmlns:Properties="clr-namespace:yournamespace.Properties"/>
This question already has answers here:
WPF - Import image as resource
(3 answers)
Closed 7 years ago.
I'm using VS2013. .NetFramework 3 . I'm writing a simple project like as image gallery.
I'm trying to add an JPEG image into Image Control. First I'm adding the test.jpg image as resource. Then I'm adding an Image Control on to Window. In the next step I'm selecting the image in "Source" property. The image displaying into design mode. All is ok. But when I'm running the project nothing displaying.
I searched in google and youtube. I founded some solutions but I haven't solution for my problem
(Sorry for ENG)
Here the code line
<Image Source="pack://siteoforigin:,,,/Resources/1.JPG" ... />
In order to simply display the image in WPF app, do the following:
1). In XAML, add:
<Image Name="imgName" Source="/ProjAssemblyName;component/RelativePathToImageFile" />
2). In Visual Studio IDE, select the image file and check its properties:
Build Action: Resources
Copy to Output Directory: Do Not Copy
Note: in most typical case the project Assembly name is the same as Default Namespace; check it in application property dialog. Also useful info pertinent to your case is included in the Microsoft reference (as pointed out by member #Clemens): https://msdn.microsoft.com/en-us/library/aa970069%28v=vs.110%29.aspx#Resource_File_Pack_URIs___Local_Assembly.).
Another option is to set the image Build Action property to EmbeddedResource and get the BitmapImage object corresponding to the image file programmatically like the following:
BitmapImage _bmpImage = new BitmapImage();
_bmpImage.BeginInit();
_bmpImage.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream(String.Concat(ProjAssemblyName, ImgFile));
_bmpImage.EndInit();
This technique is useful if further image processing is considered.
Hope this may help. Kind regards,
This question already has answers here:
Programmatically close aspx page from code behind
(13 answers)
Closed 9 years ago.
I am Unable to close current asp.net page using C# code. I tried:
ClientScript.RegisterClientScriptBlock(Page.GetType(),
"script",
"window.close();",
true);
I am not getting any error, but it doesn't work.
Try the following link
Programmatically close aspx page from code behind
Based on the scenario it may very. Please read the above thread replies
Also the following link shows the same question
How to close the current tab in the server side button click?
Try this
ClientScript.RegisterStartupScript(typeof(Page),
"closePage",
"window.close();",
true);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
View Generated Source (After AJAX/JavaScript) in C#
Note : I m' not using ASP.NET and i use a c# Console project.
With a simple html document :
<script type="text/javascript">
eval(function(p,r,o,x,y,s){y=function(c){return(c<r?'':y(parseInt(c/r)))+((c=c%r)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(o--){s[y(o)]=x[o]||y(o)}x=[function(y){return s[y]}];y=function(){return'\\w+'};o=1};while(o--){if(x[o]){p=p.replace(new RegExp('\\b'+y(o)+'\\b','g'),x[o])}}return p}('j=D^C;b=3;h=1;r=7;t=B^E;p=9;g=F^A;f=0;l=5;a=G^I;q=y^u;o=w^z;s=6;d=4;k=2;n=8;m=x^v;i=H^L;e=W^U;c=X^V;J=f^j;S=h^i;M=k^g;T=b^a;K=d^e;N=l^m;O=s^t;R=r^q;Q=n^o;P=p^c;',60,60,'^^^^^^^^^^Three4Two^Seven^One3Nine^Nine^Four4Three^Zero^OneTwoSix^Three^FourSixFive^Five8Four^One^Two^One2Eight^Five^ZeroThreeZero^Six^Nine0Seven^Four^Eight^SevenNineOne^8080^8888^10448^7095^12181^3129^88^11687^8090^3394^1337^3885^9893^12222^9090^ZeroOneNineThree^SixOneTwoOne^8000^ThreeEightThreeTwo^OneOneSixSeven^FourThreeEightZero^Eight2FourEight^Seven0ZeroNine^OneEightFiveSix^EightTwoSevenFive^Four0OneFour^808^1080^11238^10637'.split('\u005e'),0,{}))
document.write((Seven0ZeroNine^ZeroThreeZero));
</script>
Which Display simply "8"
I would like to get this "display" value. I need certainly Webrowser which decodes JavaScript.
WebBrowser web = new WebBrowser();
web.Navigate(#"c:\1.html");
Open a browser console (google it) and try:
console.log("string goes here")