Setting window icon in Avalonia - xaml

I am writing a small app for as a school project and I cannot figure out how can I change the window icon. I found the "Icon" property of Window, but I have no clue how it works, as I have found little documentation on it. When I tried to input something in the field, it threw an error, that the resource could not be found. I read something on importing resources as well, but this is my first app of this kind, so I am completely lost. Any help much appreciated, thank you

You need to add your icon as AvaloniaResource. If you are using MVVM template, everything in Assets directory should be added as one. If you aren't, then add
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
to your .csproj file.
Then put your icon into Assets directory.
After that simply writing Icon="/Assets/your-icon.ico" in your window xaml should work.

This was more what I was looking for, in setting the icon in c#.
IBitmap bitmap = new Bitmap(AvaloniaLocator.Current?.GetService<IAssetLoader>()?.Open(
new Uri($"avares://{Assembly.GetExecutingAssembly().GetName().Name}/Assets/example.png"))
);
var exampleWindow = new Window()
{
Title = "Example",
Height = 700,
Icon = new WindowIcon(bitmap)
}
in axaml
<Window xmlns="https://github.com/avaloniaui"
Icon="/Assets/example.png">
...
</Window>

Related

Disable the back button in navigation bar

I need to get rid of only the arrow in the navigation bar in Xamarin forms. I tried in but I didn't get a proper solution. please help me overcome this issue. Thanks in advance.
!! I NEED TO REMOVE PERMANENTLY
solutions that I'm tried up to now :
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
IsEnabled=false
});
but still, this didn't help me
There is a easy workaround to solve this.
You could override a Icon with a transparent png file(Follow is a transparent png):
and set enabled be false as follows:
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
IconOverride = "transparent.png",
IsEnabled = false
}) ;
Then the effect as follows:
Note: You will see that we also can tap that area, therefore we need to set enabled be false.
Based on this official sample to test that.
You can set this using the Xamarin.Forms.NavigationPage class, from within a view's code behind file. E.g. within a ContentPage's constructor.
NavigationPage.SetHasBackButton(this, false);

Xamarin.Forms - Looking for a Popover

I'm working in a Xamarin.Forms project (iOS & Android) that needs something similar to the Bootstrap Popover. I didn't find something similar in the docs.
Q:
Does anyone know a Nuget Package or something similar that in order to include that UI component to a Xamarin.Forms project?
PS: Yes, I tried searching in Google and I could not found a solution.
I think Rg.Popup is a good solution...
// Use these methods in PopupNavigation globally or Navigation in your pages
// Open new PopupPage
Task PushAsync(PopupPage page, bool animate = true) // Navigation.PushPopupAsync
// Hide last PopupPage
Task PopAsync(bool animate = true) // Navigation.PopPopupAsync
// Hide all PopupPage with animations
Task PopAllAsync(bool animate = true) // Navigation.PopAllPopupAsync
// Remove one popup page in stack
Task RemovePageAsync(PopupPage page, bool animate = true) // Navigation.RemovePopupPageAsync
Try out CPOP. It's a popup plugin for Xamarin.Forms (iOS, Android, UWP). It's not the prettiest of the popups, but you can modify the colors. (Also, I think this is the only popup plugin available out there)
NuGet Package: https://www.nuget.org/packages/Calvagna.CPop/
Hope it helps!
I'd try SlideOverKit, it might do more than you need, but it has a nice range of ways of doing popover type things.

AppBarButton.Icon doesn't change on runtime

I have a problem updating AppBarButton Icon on runtime depending on some conditions.
<AppBarButton x:Name="WeekButton" Click="OnClick" Label="SomeText"
</AppBarButton>
I'm trying to update Icon property in some code behind with this code
WeekButton.Icon = new FontIcon() { Glyph = Runtime_Value_Here};
But nothing happens. The button doesn't change. But in any random time when the code works, It MAY change the button. I always see, that the Icon is new in code, but not on screen. None of the UpdateLayout helps.
Would appreciate any help.
Thanks
UPDATE:
It seems to not working with FontIcon, as with BitmapIcon changing everything works fine.
Force InvalidateArrange and it works
WeekButton.Icon = new FontIcon() { Glyph = "\uE29B", FontFamily = new FontFamily("Segoe UI Symbol")};
WeekButton.InvalidateArrange();
I believed you already found the solution with bitmap icon.
But some people who reached this page and want to know the solution like me,
Here is using bitmap icon and changing app-bar button icon dynamically.
BitmapIcon _bitmapIcon = new BitmapIcon();
_bitmapIcon.UriSource = new Uri("ms-appx:///Assets/yourBitmapIcon.png");
WeekButton.Icon = _bitmapIcon;
Try using the IconUri in order to give the value.
WeekButton.IconUri = new Uri("/Images/pause.png", UriKind.Relative);
Reference: Disable/Enable applicationbar Button in runtime with event textchanged (Windows Phone)

Dojo grid inside titlePane not getting painted until the browser is resized

I have an dojo enhanced grid inside a title pane which inturn in Tabcontainer. I am creating a tab container dynamically and painting the title pane which contains grid. For the first time the grid is painted properly but if i close the tab and again try it to open a tabcontainer title pane is painted but grid inside the titlepane is not painted (or rather its not visible) until i do a browser resize.
So anybody have faced similar kind of issue? Please let me know the solution for this.
I tried resize(), update() & startup() methods on grid nothing worked out.
I am kind of stuck please share your thoughts on this.
Thanks,
Vikram
I had the same problem and found a workaround by doing a dojo connect like:
dojo.connect(Datagrid,"_onFetchComplete",DataGrid,"_resize");
So it should automatically be resized, when DataGrid finished loading data.
Hope I could help.
Greeting, Simon
Have you tried setting an absolute height on the Grid?
Which browsers did you try? (I experienced various problems with DataGrid in TabCointainer using IE)
You must call the TabContainer.layout() each time its container is changing size. For doing this, you could 1) monitor DOMEvents onunderflow and onoverflow on containing DOMNode or 2) when container becomes visible (once-n-forall).
Reason why a window.onresize event fixes it is, that the TabContainer hooks on said event and calls its own layout.
In your situation, where the TabController fiddles with TabContainer's panes, there may be missing a 'layoutChildren' somewhere. Optimally, you should place the grid as the first on only child to tab.
After the grid is deployed, it will take an absolute, calculated height - 'inherited' from the TabContainer. This is fired once the TabContainer chooses to resize or instructed to do so.
Manually, you should be able to implement these lines - after re-opening a tab. The script is taken from _Grid.js to illustrate
var grid = dijit.byId('MYGRIDID');
require(["dijit/layout/utils"], function(layerUtils) {
layoutUtils.layoutChildren(grid.domNode,
grid._contentBox,
[grid.tablist, {
domNode: grid.tablistSpacer,
layoutAlign: titleAlign
}, {
domNode: grid.containerNode,
layoutAlign: "client"
}]);
grid._containerContentBox = layoutUtils.marginBox2contentBox(grid.containerNode,
{
domNode: grid.containerNode,
layoutAlign: "client"
});
// note this line in particular
grid.selectedChildWidget.resize(grid._containerContentBox);
}
My issue
I had a similar situation as yours:
Grid is in a titlepane (closed by default).
Grid can be destroyed and re-created on the fly.
Issue appears when user:
opens the pane.
closes the pane.
re-creates the grid.
re-opens the pane.
grid is not visible, until browser window is resized!
My solution
My approach was to force a resize() on my grid whenever the title pane was being opened.
I used code like this, in a place where I had access to both the grid and the panes:
var titlePane = registry.byId("title-pane-id");
var handle = aspect.after(titlePane, "toggle", function(deferred) {
if (titlePane.open) {
grid.resize();
}
});
The dojo/aspect doc
Don't forget to remove the aspect from your grid if you destroy it.
I did this on dojo v1.8.1
My solution is too easy: define on declaration of grid the bold parameter write here:
grid = new EnhancedGrid({id: 'MyIDgrid',
store: dataStore = new ObjectStore({objectStore: myStore}),
structure: structureGrid,
plugins: pluginGrid,
style : 'width: 725px; height: 350px',
autoWidth : true,
**autoHeight : false,height:'200px',**
elasticView : '2'
}, document.createElement('div'));
this resolve all!
Enjoy!
style="height: auto;" will fit the purpose.

SmartGWT pdf export

Has anyone successfully used SmartGWT 3.x pdf export?
My client code looks like this:
DSRequest requestProperties = new DSRequest();
requestProperties.setExportFilename("File.pdf");
requestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
requestProperties.setContentType("application/pdf");
RPCManager.exportContent(table, requestProperties);
When the code run nothing happens. Do I have to do anything server side?
I can just add that my application is successfully using the SmartGWT excel export from the list grid.
I also tried in vain to find the documentation about this. But it's not that hard. Your code seems right, have added a canvas to print and the line requestProperties.setDownloadResult(true);
final Canvas canvas = new Canvas();
canvas.setWidth(300);
canvas.setBorder("2px solid Red");
DynamicForm formPrint = new DynamicForm();
formPrint.setWidth(200);
formPrint.setHeight(100);
formPrint.setTop(20);
formPrint.setLeft(50);
formPrint.setBorder("2px solid Black");
TextItem textItem = new TextItem();
textItem.setName("NameBo");
textItem.setTitle("Title");
textItem.setValue("Value goes here...");
formPrint.setFields(textItem);
canvas.addChild(formPrint);
canvas.draw(); // to view onscreen
DSRequest requestProperties = new DSRequest();
requestProperties.setExportFilename("File");
requestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
requestProperties.setContentType("application/pdf");
requestProperties.setDownloadResult(true);
RPCManager.exportContent(canvas, requestProperties);
I then added the following jars from the smartgwtEE lib folder (in eclipse .classpath)
<classpathentry kind="var" path="SGWTEE_HOME/lib/isomorphic_contentexport.jar"/>
<classpathentry kind="var" path="SGWTEE_HOME/lib/iText-2.0.8.jar"/>
<classpathentry kind="var" path="SGWTEE_HOME/lib/jtidy-r938.jar"/>
And that's all that was to it :-)
The answer to your question is yes: countless developers have successfully used SmartGWT's PDF Export. Now gimme my points please ;)
To troubleshoot, look in your server logs for errors.