How to reference an icon resource file reference in XAML - xaml

I'm trying to get a button to display an icon in XAML. Initially I wanted to paste a character instead, but vb Express 2008 would not recognise it being a symbol as it is not a regular character. Then I created an icon and tried to set the button image property to reference it, but this does not exist, so more misery. Now I've used the project resources to add the icon file which it has shoved in the project resources directory.
What I want to do is use XAML to display the icon, in this tag:
<Button>
<Image Source="{StaticResource UpArrow}"/>
</Button>
I ideally want to have the image in a separate file and reference it by the project. I am a bit confused by the content/resource issue.
I tried to access it using:
<UserControl.Resources>
<BitmapImage x:Key="UpArrow" _
UriSource="Resources/_25B2_Triangle__black__up_pointing.ico" />
</UserControl.Resources>
I've read some stuff about the pack assembly which is massive and confusing. Surely, putting an icon into the resources file should make it easy to reference using /Resources or similar, instead of the absolute file path, otherwise, what is the point of it?
I am wanting to do it all in XAML rather than code-behind because then this work would all be done by the client, but maybe I am not undestanding when to use code behind. With WPF, there is very little written about what you are trying to do at the large scale and why you would want to do it, apart from MS constant refrain of how 'cool' it is, -which is not very helpful.
Thanks..

The easiest way to do this is:
<Button>
<Image Source="Resources/_25B2_Triangle__black__up_pointing.ico"/>
</Button>
The important thing to remember is to make sure that your icon file is recognized as a valid Resource by your application. With WPF, there is one more step you need to take versus the old winforms way of doing it.
In your Solution Explorer, expand the 'Resources' folder, then click on the "_25B2_Triangle_black_up_pointing.ico" file. Then press F4 for properties. Make sure that the 'Build Action' property is set to 'Resource'.

Related

How to override default WinUI 2.x styles in Blend?

Previously I had asked where to find the default styles for the WinUI 2.x controls, and was pointed to the appropriate repository in GitHub where those could be found. Thanks! However, what I really want is to be able to override some of the styles. I was expecting that I would be able to do so in Blend, but I have not been able to figure out how to do that.
For example, when I load my project in Blend and then try to edit the templates for the ContentDialog, I am offered the option to apply an existing style, but not to create a new one. I was expecting I could create a copy, which would give me the default styling as a starting point and allow me to make the small modifications I require. Regarding buttons, I was able to edit a copy of the template, but that only gave me access to the ControlTemplate where I want access to the equivalent of DefaultButtonStyle.
It has been a while since I've used Blend, so perhaps I am mis-remembering how the tool works. But in previous versions of our app I was able to generate resources that included the full styling of the controls that I was using, such as buttons and content dialogs. Can I do the same for our current app that uses WinUI 2.x? If so, how? And if not, what are my alternatives? I have considered copying the default templates I am interested in into the resources of my project and making modifications that way, but I am hopeful that there is a better way.
Rich
I am offered the option to apply an existing style, but not to create a new one
This is expected. For example, both the Visual Studio or the Blend for Visual Studio can't directly create a default DropDownButton style of WinUI. You need to manually copy the WinUI style from Github and put the style in your XAML.
For native UWP controls, you could just generate a copy of the style automatically.

How to create a bootstrapper with a log window

Currently I'm using the standard WixStandardBootstrapperApplication.HyperlinkLicense bootstrapper theme.
This theme doesn't show much information during installation. I was wondering if there is a theme that shows the log output of each installer it executes. Maybe after clicking an advanced button. I've seen this in a few installers but of course I do not know for sure if these were made with Wix.
I've tried inspecting the existing themes with ThmViewer.exe but unfortunately this program either crashes, or displays no preview window.
I've found a reference to something called the ExecuteProgressActionDataText here
<Text Name="ExecuteProgressActionDataText" X="11" Y="163" Width="-11" Height="17" FontId="3" DisablePrefix="yes" />
But unfortunately I cannot get my bootstrapper to launch if I use the supplied theme file. I think I need a complete theme file, but I'm not sure where to find the original one for the WixStandardBootstrapperApplication.HyperlinkLince theme.
Any thoughts on how to create a bootstrapper with a log window?
Update:
I've found the original xml of the HyperLink theme here. Using that I've added the ExecuteProgressActionDataText element to my UI. Its a single label that displays a lot of events. But unfortunately its not a listbox or something like that which makes it quite useless. (There are way too many messages per second to make sense of them in a single label).
The theme file seems to be driven by WixStandardBootstrapperApplication.cpp and unfortunately I do not see any other variables defined there that have a name that indicates that they do what I want :(.
You have to modify the bootstrapperapplication.cpp to implement the listview yourself. You can add the view in the wix theme I believe but you would have to alter OnExecuteMsiMessage so that instead of using ThemeSetTextControl(....) you have to add a new list item to the listview. You should be able to do anything you want in the bootstrapper application with regards to the UI just need to figure out how

VB.NET Adding an image so that it shows up under My.Resources.TheImageName

Using VS2012, I would like to add an image to the My.Resources. namespace.
I would like to draw this image to a PictureBox on the Paint event.
I did the following:
I clicked "Add existing item", then I opened up the image.
I clicked the image from the Solution Explorer and set the Build Task to "Embedded Resource".
I saved the project and re-built it.
But it still does not show up under My.Resources.
What did I do wrong, please?
Thank you for the help!
ps:
I do not want to add it directly to "Resources.resx" (for example by clicking the "BackGroundImage" property of a form).
I would prefer having the image in the solution explorer instead. I once experienced that VS2012 once damaged a file, and I had to rebuild the resource file. I would like to avoid it.
You need to add the image to the Resources tab in Project Properties, not to the project directly.

Word 2010: how to create a drop-down menu in qat (quick access toolbox)

SHORT:
I would like to add a drop-down menu to the quick access toolbar of any instance of Word 2010 via placing a customized .dotm-file in Word's startup folder. I fail in creating this customized .dotm-file.
LONG:
I've been writing a little "add-in" for Word 2010, first with VSTO, then figured out problems with the deployment, now with VBA. The add-in should simplify adding my company's logo and legal notice to documents (different combinations of logos & legal notices exist).
In order to allow selection of wished logo and legal notice with as few clicks as possible, I thought about automatically adding a drop-down menu to the quick access toolbar (qat). I want to do this by placing a .dotm-file containing the code for this qat-extension & the logic for the header/footer-setting in the user's Word startup-folder.
I have already succeded in adding such a drop-down menu to the Add-Ins-Ribbon using CustomUI, everything works fine on the code side. Via the menu the user can choose from all presets supplied and headers and footers are added successfully.
Furthermore, I have seen and played with examples that successfully add controls directly to the qat.
If placed in my startup-folder, these examples do a perfect job and the controls defined therein appear on any instance of Word. The way to go is to create a new folder "userCustomization" in the .dotm-document and then create the customUI.xml-file with several restrictions (no custom icons allowed e.g.).
Unfortunately, I was not able to figure out how to implement a drop-down-menu control in the qat. All the examples I found only used "simple" (button) controls and no matter how many times whatsoever I tried wrapping buttons in a tag, i never got it working.
I can on the other hand manually add my ribbon via "qat => add controls" to the qat and .. voilà .. it's there, working exactly as wanted, so i suppose it must be possible. But what I need is to automate this so that our users don't have to do any configuration of the qat.
Help would be very much appreciated! Best regards from Germany,
Kurt
This is how the drop-down menu is added to the Add-Ins-tab:
<ribbon>
<tabs>
<tab idMso="TabAddIns">
<group id="MyGroup" label="WordDesigner" visible="false">
<menu id="myMenu" label="Design einfügen" size="large" image="menulogo">
<menu id="mySubMenu" label="Rechnungswesen" image="icon2">
<button id="MahnUndKlage" label="Mahn- und Klage" image="icon3" onAction="DesignAnwenden"/>
<button id="Buchhaltung" label="Buchhaltung" image="icon3" onAction="DesignAnwenden"/>
</menu>
<button id="Personalabteilung" label="Personalabteilung" image="icon3" onAction="DesignAnwenden"/>
<button id="Verkauf" label="Verkauf" image="icon4" onAction="DesignAnwenden"/>
<button id="clearHeaderAndFooter" label="Gestaltung entfernen" image="icon5" onAction="DesignAnwenden"/>
</menu>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Usefull information I found included:
Greg Maxey on modifying icons in the qat
in german, part 18 of an introduction to
RibbonX
Alright, some more research has led to some more information ( ... ) and in case anybody else might ever search for a similar question, I'll try to conclude what i got..
1) According to this MS page on the QAT, only Button,
ToggleButton and CheckBox are valid items for the QAT in Win7 (Win8
allows some more controls).
Since you can manually add drop-down-menus as well, I thought there had to be some way to do that automatically as well as with buttons, checkboxes and togglebuttons
I could for the life of me not figure out a way to auto-add a
drop-down to the QAT by modifying the customUI.xml-file in the userCustomization-Folder of a .dotm-file in startup folder.
There is one other possibility to achieve that goal: Office 2010 uses
a file of the type ".officeUI" where it stores each users elements
from the QAT (e.g. Word.officeUI). In there, adding the following xml-Element will make sure that, if you have placed the .dotm-file containing your menu in
Word's startup folder, it is on load displayed as a drop-down in the
QAT:
<mso:control idQ="x1:myMenu" visible="true"/>
Unfortunatly, enthusiastically adding this xml-Element to the customUI.xml in userCustomization results in .. poof .. no user defined extra icons in the QAT at all (customUI.xml is corrupt).
Furthermore, a great ressource I stumbled upon yesterday is Andy Pope's Visual Ribbon Editor. You can easily tweak the Ribbon and QAT.
I know I'm late to the game, but I found this post via Google and figured you'd appreciate an answer.
You can create the appearance of a menu through Word's QAT with a little VBA trickery. Basically, create a custom command bar with each "Control" representing a slot on your desired menu. You can use ".BeginGroup" to create a divider line to separate items if you wish. Your menu can go at least a couple levels down, but for complexity's sake, I wouldn't recommend going too deep.
When your command bar is perfect, create a macro that only displays your command bar as a popup when run:
Application.CommandBars("My Command Bar").ShowPopup
Add a shortcut to that macro to the QAT. When you click that shortcut, your command bar will appear as a popup menu at your cursor, which is the desired effect.
Enjoy!

Is there an easy way to make a code TextBox?

Is there an easy way to make a code TextBox?
I'm trying to make my own limited/specialized version of XAMLPad.
Displaying the current XAML object tree in the top display is simple enough, using XamlReader.Parse() ... But I'd like the actual XAML code in the bottom window to show up in its appropriate colors.
Here is an example of something similar to what I want.
(source: usefulfreeware.net)
The above example looks pretty authentic, with the little expander/collapser thingies on the left side as well as close-to-standard coloration of XAML tokens.
I believe that this doesn't have to be created from scratch, so I'm asking SO if anyone knows where I might find automated support for this type of "code" display.
Kaxaml uses ICSharpCode.TextEditor, the text editor component from SharpDevelop.
Have a look at sharpdevelop - we use it for an internal iron python editor