Can we convert vector to C# code? (not to XAML)
Hello,
I'd like to know if it's possible to convert/import an externally-drawn vector as a Path in C# code. So far I've only found how to import a vector to XAML. I'm making a WP8.1 WinRT app and I'm going by what is said on
this page (which is for vector to XAML conversion). The answer says you can't use the XAML code as the Path.Data in code, but is there an alternative way of doing this?
Basically, my app has many instances of ~6 buttons that have a custom icon/image set as their Content. The button instances are created programmatically and inserted into one/more stackpanels on the page. Currently I'm using .png images. But since WinRT
doesn't have OpacityMask I have to supply two versions of each png: one for Dark and one for Light theme. Then I need to check for the Application.Current.RequestedTheme and set the png appropriately. This, and the reported shorter processing time of Paths
is why I'm considering switching.
I'm thinking the Path Data would be from an imported vector (as PathGeometry). And the code that generates the buttons would be
myButton.Content = myPath; instead of myButton.Content = myImage;
But since we can't use the XAML Path Data in C#, I'm very much stuck here.
Is it possible to achieve the same thing through another method? I was thinking that maybe one could create a UserControl containing the path and set the UserControl as the button's Content in code. But I'm unfamiliar with UserControls. Or is there a way to
convert a vector to C# code directly?
Thank you, that's exactly what I want.
But the weird thing is, the Path inside the buttons show up only the first time that they're being rendered on a page. When I navigate to another page with instances of buttons that use the same paths, the buttons become blank... And when I go back to the
page that initially did display the buttons correctly, I find that its buttons are now blank as well! I can replicate this in a blank app.
Here's a basic sample of what I'm talking about:
App.xaml
<Application.Resources>
<ResourceDictionary>
<Style x:Key="ExponentPathStyle" TargetType="Path">
<Setter Property="Data" Value="F1M9.033,19.5L0,19.5 0,4.438 8.686,4.438 8.686,7.2 3.392,7.2 3.392,10.551 8.318,10.551 8.318,13.303 3.392,13.303 3.392,16.748 9.033,16.748z M10.541,6.646L10.869,6.596 11.046,7.109C11.18,7.226 11.317,7.285 11.457,7.285 11.737,7.285 12.031,7.145 12.34,6.865 12.648,6.585 13.2,5.806 13.995,4.529 13.832,3.313 13.646,2.435 13.436,1.894 13.226,1.354 12.961,1.083 12.642,1.084 12.463,1.083 12.27,1.153 12.062,1.294 11.855,1.434 11.637,1.644 11.407,1.924L11.071,1.756C11.424,1.28 11.774,0.784 12.121,0.269 12.3,0.179 12.471,0.112 12.634,0.067 12.796,0.022 12.95,0 13.096,0 13.6,0 13.979,0.178 14.234,0.533 14.489,0.889 14.698,1.75 14.86,3.117 15.533,2.047 16.023,1.33 16.331,0.966 16.639,0.602 16.944,0.339 17.247,0.176 17.46,0.059 17.681,0 17.911,0 18.079,0 18.241,0.05 18.398,0.151L18.171,1.613 17.911,1.68C17.832,1.411 17.656,1.277 17.381,1.277 17.084,1.277 16.78,1.409 16.469,1.672 16.159,1.935 15.664,2.588 14.986,3.63 15.261,5.277 15.485,6.298 15.659,6.693 15.832,7.087 16.062,7.285 16.348,7.285 16.471,7.285 16.607,7.246 16.755,7.167 16.904,7.089 17.21,6.862 17.675,6.487L17.877,6.781C17.16,7.464 16.614,7.918 16.238,8.142 15.986,8.293 15.743,8.369 15.507,8.369 15.3,8.369 15.105,8.271 14.923,8.075 14.741,7.879 14.575,7.484 14.424,6.89 14.401,6.8 14.294,6.201 14.104,5.092 13.426,6.19 12.926,6.946 12.604,7.36 12.282,7.775 11.984,8.058 11.709,8.209 11.53,8.316 11.309,8.369 11.046,8.369 10.81,8.369 10.561,8.288 10.298,8.125 10.415,7.672 10.497,7.179 10.541,6.646z" />
<Setter Property="Fill" Value="{ThemeResource PhoneForegroundBrush}" />
<Setter Property="Height" Value="19.5"/>
<Setter Property="Width" Value="18.398"/>
<Setter Property="Stretch" Value="Fill"/>
</Style>
</ResourceDictionary>
</Application.Resources>
Above is just one of the Paths that I'm using. Note: its Fill is set to ThemeResource PhoneForegroundBrush.
MainPage.xaml
<Button
Height="100"
Width="100"
Click="Button_Click"
x:Name="btnmainpage" />
Button_Click navigates to BlankPage1 which contains the same button (different name)
MainPage.xaml.cs Constructor
this.NavigationCacheMode = NavigationCacheMode.Disabled;
Windows.UI.Xaml.Shapes.Path mypath = new Windows.UI.Xaml.Shapes.Path();
mypath.Style = (Style)App.Current.Resources["ExponentPathStyle"];
btnmainpage.Content = mypath;
By setting NavigationCacheMode.Disabled I force the page to "build" the button & its content every time I navigate to it. So I'm effectively simulating navigating to infinite "different" (but not really!) pages like this, I think
BlankPage1 contains the same button as MainPage (to prevent confusion, I've called this
btnpage1) which navigates back to MainPage. In BlankPage1's constructor, the code is the same as well, except btnmainpage is replaced with btnpage1.
So the button on MainPage navigates to BlankPage1, whose button navigates us back to MainPage etc. and both pages are not Cached. When I enter the app, the path displays correctly on the button, but upon subsequent navigation the button on either page is
blank. Setting the fill color in code explicitly didn't work either:
mypath.Fill = (SolidColorBrush)Application.Current.Resources["PhoneForegroundBrush"];
Is this a bug or am I doing something wrong here?
Similar Messages
-
Can i set the policy in code not in a policy file
normally starting rmi client with a policy file. and start the client with such JVM parameters: java.security.policy and java.rmi.codebase.
But in jsp how can i specify these JVM parameters.Or can i make the policy in code not in
a file.You can specifiy inline with code otherwise malicious code would use it the grant all permissions before it wrecks havoc on the system.
When your Servlet engine starts (Tomcat, JBoss, depends on which you are using) there will either be an option to pass in additional policy file, or a policy file will exist inthe servlet engine directory path for you to edit and add your entries to. -
Photoshop CC Can't convert to jpegs; image processor not opening
I'm on Windows 7. When I open a psd document in PS CC, I don't have the option to convert to jpeg, and a lot of other types, for that matter. Also, when I click on Tools/Photoshop/Image processor it will not open up. Any suggestions? Thank you.
It was already disabled when I checked. I enabled it and tried again, still didn't work. Anything else that might be wrong? i'm getting desperate lol
-
How can I convert characters into ascii code numbers ??
Read the characters or String from keyboard input then I want the sum of the ascii code of the String or the characters. Please help ....
HanRead the characters or String from keyboard input
put then I want the sum of the ascii code of the
String or the characters. Please help ....
HanThe keyboard input part is a little more coding envolved. Here is a sample of what can be done if
you know what to implement. It needs three classes
from the java.io package. Well, here is the complete
source code for the 'keyboard input' and a driver
class to test it.
//package consoleclass;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class Driver
public static void main ( String[] args)
System.out.println("Enter a number");
int number = MyInput.readInt();
System.out.println("number entered "+ number);
System.out.println("Enter another number");
number = MyInput.readInt();
System.out.println("number entered "+ number);
class MyInput
/**Read a string from the keyboard*/
public static String readString()
BufferedReader br
= new BufferedReader(new InputStreamReader(System.in), 1);
// Declare and initialize the string
String string = " ";
// Get the string from the keyboard
try
string = br.readLine();
catch (IOException ex)
System.out.println(ex);
// Return the string obtained from the keyboard
return string;
/**Read an int value from the keyboard*/
public static int readInt()
return Integer.parseInt(readString());
/**Read a double value from the keyboard*/
public static double readDouble()
return Double.parseDouble(readString());
} -
Can't Order Book. Postal Code not accepted
I've spent days and nights.. creating a Book in Iphoto from my latest vacation.
Now when i'm finished i cannot order since my Postal Code(Zip Code) isn't accepted.
I live in Sweden and no matter what ZIp Code or variations of it i try (believe me i have tried) i cannot get past step2. I always get the dialog that i need to eneter a valid postal code.
I've searched the web and tried (just to get past the second step) postal codes for a few other countries, and the ONLY one working is when i try a US address and ofcourse select USA as the country.
I've tried with a new account, and with an existing account that works fine with itunes... Anyone have any ideas, or have i just wasted days creating a book i cannot order..Wiped
Welcome to the Apple user discussionforums
here is a link to the Swedish page on ordering problems with a form to request help from Apple - http://www.apple.com/se/support/photoservices/account_troubleshooting/ -
I create name plaques using TypeStyler, but my laser cutter says they must be converted into two vector files; a cut file to cut the outlines of all the letters and an "etch" to etch the letter intersect lines. Can AI convert my TypeStyler file into a cut file and an etch file?
Thanks. I might use it soon...
Does it automatically make folders named after the volume labels? And does it handle the conversion of spaces and non-alphanumeric characters to octal codes?
I could read the script but it would be faster for everyone reading, if you leave the answer as a reply.
I also think that there should be some major work done on modernizing the fstab, either by replacing it with a better implementation of file system mounting or changing the file structure and adding in better handling of non-alphanumerics. I don't want to have to look up a stupid octal table every time I type in my labels. -
Just upgraded Tiger to Leopard. Clarisworks not supported. I can successfully convert CW4.0 doc's to AW6.0 doc's using MacLink Plus Deluxe and then work on them but the problem is that I cannot print them. Neither can I convert to PDF.
If I was trying to get someone else to do my work,
I wouldn't be posting this saying what I have said
would I? I'm not unwilling to do the work myself.From what was stated in your OP, it seemed that you
were.I'm sorry if it seemed that way. I don't want something for nothing. I've spent MANY hours, which I don't have, trying to work this out. I have hit a point where I don't think my expertise is going to solve the problem. That's why I've turned to some experts who might say something along the lines of, "Hey, I know what that is...you're compiling against... and on the Unix box, it's compiling against..." I was NOT looking for something like, "See the code below that fixes your problem."
The only problem is that I don't have direct access
to the sun unix machines I'm running the app on,
so I can't run a profiler on it. Ah, okay. So the only knowledge you have of how it
performs on those machines is from your instructor
running it and then telling you how long it took?No. I can SSH into the servers and run the program from a command line. But I wouldn't be able to install any profiler programs.
You could ask your prof to run it with -Xprof or
-Xhprof or whatever. Or you could put in a bunch of
timing statements to get a rough idea of which parts
are making it take that extra 39 minute or whatever.is -Xprof a java command line option? If so, I will look into doing that. Maybe it's available on the machines at school. Thanks for that input. -
hi everybody.....
can anybody provide me a java code for the following problem......
i want that if user enters input like this:
sam,john,undertaker,rock
the output should be:
'sam','john','undertaker','rock'
i.e , is converted to ',' and the string starts with ' and ends with '
i have a javascript code for this and it is reproduced below to have full view of the problem.........
<HTML>
<BODY>
<script type="text/javascript">
function CONVERT(){
var re=/[,]/g
for (i=0; i<arguments.length; i++)
arguments.value="'" + arguments[i].value.replace(re, function(m){return replacechar(m)}) + "'"
function replacechar(match){
if (match==",")
return "','"
</script>
<form>
<textarea name="data1" style="width: 400px; height: 100px" ></textarea>
<input type="button" value="submit" name="button" onclick="CONVERT(this.form.data1)">
</form>
</BODY>
</HTML>
can anyone do it for me.
thx in anticipationSunish,
On your problem, check in the String class documentation the method replaceAll(), you can solve your problem in just one line of code.
As for why the serious poster(the ones that are here to help, for many year, instead of just disrupting the forum) do not give you code is that they are here to help people learning and not to give free code.
You help a person to learn, when you provide this person with the tools to research and help the person to think out of his problem, so that in the future the learning person can repeat the process by herself instead of going after finnished solution everytime he needs it.
May the code be with you. -
How can i convert my codes of ultra violet to iTunes codes ?
I have purchase tones of movies but they have codes inside, some are accepted to use in itunes and others are not i would like to kow how can i convert those codes to input to my itunes so i can take the movies anywhere i go
You cannot.
B-D wrote:
My iphone 4s wont let me access the phone and keeps saying 'the SIM car inserted in this phone is not supported...'...
Contact your Carrier. -
How can I convert multiple files at one time and not one at a time
How can I convert multiple files at one time and not one at a time
Hi Plissey1950,
Sorry for the lengthy delay to a response. Are you trying to convert multiple files to individual PDF files at the same time? (not combine them). If so, you'll need to use Adobe Acrobat for this function. The CreatePDF service does not have the ability to convert multiple files to multiple individual PDF files.
Thanks,
David -
How can I convert a video I took with my ipad on the format IMG to a supported format for Youtube?
To upload videos to YouTube we have to make sure videos are in a format that YouTube accepts. Here’s the list of some well-known video formats which YouTube supports:
WebM files (Vp8 video codec and Vorbis Audio codec)
MPEG4, 3GPP and MOV files – (typically supporting h264 and mpeg4 video codecs and AAC audio codec)
AVI (Many cameras output this format – typically the video codec is MJPEG and audio is PCM)
MPEGPS (Typically supporting MPEG2 video codec and MP2 audio)
WMV)
FLV (Adobe – FLV1 video codec, MP3 audio)
But I think you get the wrong video file. iPad recorded video files are in m4v, mp4, mov, avi format but not the img files. Anyway, if you need a video converter, Format factory or iFunia video converter are good choice.
Good luck! -
How can I convert date infomation to a string just includes the date not th
I just want the date like Thu 08, july 2004 but not the exact time.
how can I do that.The prior code produces a date formatted as Jul 7, 2004
To get Wed 07, July 2004, try this minor modification:
import java.text.DateFormat;
import java.util.Date;
import java.text.SimpleDateFormat;
DateFormat format = new SimpleDateFormat("EEE dd, MMMM yyyy");
Date mydate = new Date();
String str = format.format(mydate);
System.out.println(str); -
How can I convert my Open Source document files into Word document files? I cannot download Pages since my Macbook Air does not have the most recent software. I downloaded open office to my mac to try and save money. It worked well for a while. Now I get this pop-up message that asks me to "Reopen" and when I select the option, nothing happens. I cannot save my documents anymore and I cannot convert them to word. Help!
dwb wrote:
Does OpenOffice output Word documents by default or do you have to select it manually?
You have 17 options to save as in Open Office, one of which is .doc files, yes it needs to be saved manually.
You may be able to default to DOC, but have not tried same.
Since Open Office is 99% same as Word, I use it, or Word, either one. Open Office is a bit less buggy than Word 11' -
As I opened the places.sqlite with an sqlite-editor I found out that firefox saves the last_visit_date via a timestamp which is 16 digits long. I realized that the first 10 digits are similar to the corresponding unix-timestamp but not equal. So.. how can i convert the firefox-timestamp into a normal date? Or into the corresponding unix-timestamp?
Write a bash script or 'C' program to change the date format and then use the sql update function to receive the stdio output 'where date_field='embeded date value'.
-
How can i Convert to PDF not Show the Microsoft word in Preferences Setting
hi,
i installed Acrobat 9.2.0 professional and ms word 2003 professtion,but i can't convert word to pdf,
1) File->open(doc file)
2) its show error
3) Edit>Preferences >Convert to pdf
its not Available to Microsoft word
please help me how can i add in Preferences setting
by,
Seenu1) First i install Ms Office after then i install Acrobat 9.0 and update 9.2.0
2) that time also Word to pdf Conversion display same error
3) and 3 times i reinstall acrobat but not change .
4) this error my System only show, but same config for other system is not show
how can i solve, plz help me.
by,
Seenu
Maybe you are looking for
-
Want to play games from my iPad on tv using apple tv?
Helle
-
Since upgrading to Maverics, can no longer sync Contacts via cable!
Since upgrading to Maverics, can no longer sync Contacts via cable! As I am not willing to put my Contacts data on iCloud, I am no longer able to update Contacts between MacBook, iPhone and iPad. This greatly reduces the value of these products. Any
-
i'm trying to update records and when i edit a particular value and click update it gets updated in the database but the changes are not visible in the current screen.instead if i click the update button again i can see the change.can anybody help me
-
Keyboard shortcut: switch between modules?
Hi all and thank you for your help. I have checked through the keyboard shortcuts and could not fint it: Is there a shortcut to switch between the different modules in LR 3? It will be very handy if there is something like that. Thank you so long. De
-
Change security policy on passthrough proxy-service?
I've an business-service which is secured by a OWSM policy. The business-service is exposed as a proxy-passthrough (a long with the OWSM policy). Is it possible to change the security policy for the proxy-service (which is exposing the OWSM policy se