UpdateMode for DatePicker - xamarin.forms

I want to change the update mode like here. This is my code:
this.datePicker.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished);
The first part is marked as wrong this.datePicker.On<iOS>() and it is referencing an object in the xaml. On other places the same code is working fine. Don't know what's wrong here. The error message is:
Returns the platform-specific instance of this DatePicker, on which a platform-specific method may be called.
'IPlatformElementConfiguration' does not contain a definition for 'SetUpdateMode' and the best extension method overload 'Picker.SetUpdateMode(IPlatformElementConfiguration, UpdateMode)' requires a receiver of type 'IPlatformElementConfiguration'.
Any suggestion?
Edit:
It seems that the desired behavior (updateMode) is only available for Picker and not DatePicker. See here or here. Is there a way to enable the feature also for Datepicker? How?

Using Xamarin Forms 4.6 here. Inside your custom renderer use this code:
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (e.NewElement != null && Control != null)
{
...
Element.On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUpdateMode(UpdateMode.WhenFinished);
...
}
}

Sadly, UpdateMode is not available for Date picker.
And the workaround i found,is to create a custom calendar(which i did).Custom calendar looks tough to create,but is quite simple to implement(of basic functionalities) .
With only 1 month of experience in xamarin, i've created it.
You can check out the complete code here:
https://medium.com/#bhavyajoshi2793/custom-calendar-in-xamarin-for-android-ios-windows-578f1136daec?source=friends_link&sk=9b1c97e0021da2e48ec84b5b6d4ff8e4

Related

Unable to override OnApplyTemplate

I'm trying to override the NavigationView behavior:
public partial class CustomizableNavigationView : NavigationView
{
public CustomizableNavigationView()
{
// This gets called
}
protected override void OnApplyTemplate()
{
// This doesn't
}
}
It works on UWP, but not on Android. On Android, it doesn't call OnApplyTemplate and the screen remains blank, there's not content. Questions:
Why doesn't OnApplyTemplate get called on Android? I see that here: https://platform.uno/docs/articles/implemented/windows-ui-xaml-frameworkelement.html it says OnApplyTemplate() is on all platforms
There's no error or anything displayed in the Output panne in VS while running with debugger. Should there be any in this case? Do I need to enable something to log errors?
I noticed that if I don't use partial it gaves me error saying partial is required. This is required only on Android, why is that? A more in-depth explanation would help a lot to understand how things work.
Once I figure out why OnApplyTemplate is not called, I want to do this:
base.OnApplyTemplate();
var settingsItem = (NavigationViewItem)GetTemplateChild("SettingsNavPaneItem");
settingsItem.Content = "Custom text";
My hunch is this won't work on Android. Am I correct? :)
Jerome's answer explains why OnApplyTemplate() was not getting called, to address your other questions:
You can configure logging filters for Uno, this is normally defined in App.xaml.cs. Warnings should be logged by default.
The partial is required because Uno does some code-gen behind the scenes to create plumbing methods used by the Xamarin runtime. Specifically because the control is ultimately inheriting from ViewGroup on Android, it's a native object, and requires special constructors that are used only by Xamarin's interop layer. There's some documentation in progress on this.
Try it and see. :) GetTemplateChild() is supported, and setting ContentControl.Content in this way is supported, so I would expect it to work.
At current version (1.45 and below), the application of styles is behaving differently from UWP. We're keeping track of this in this issue.
The gist of the issue is that Uno resolves the style using the current type and not DefaultStyleKey, and cannot find an implicit style for CustomizableNavigationView.
A workaround for this is to either create a named style from the default NavigationView style, or create an implicit style that uses CustomizableNavigationView as the TargetType instead of NavigationView.

XAF: How to minimize ribbon from code in XAF Windows App

I want to minimize the ribbon when user click on particular navigation Item.
For example - when User clicks on Dashboard nav item, I want the ribbon minimized, and automatically "maximized" on others.
How can I do that ?
I've found that I can simple access the ribbon in the ViewController.
So like usual in XAF, override "OnActivated" and do the magic there
protected override void OnActivated()
{
if (Frame.Template != null)
{
((XtraFormTemplateBase)Frame.Template)).RibbonTransformer.Ribbon
.Minimized = View.Id == "TestView;
}
base.OnActivated();
}
I got a couple of errors while accessing Frame.Template being NULL when I'd hit a dashboardview, with many nested ListView in it. Make sure You don't forget to check it :)
They released a hotfix for this bug in Devexpress's version 22.1.4. Today I updated to 22.1.4 while getting this error when there was version 22.1.3 and the error was completely resolved.
NullReferenceException is thrown in the MinimizedRibbonPopupForm.GetSizeWithIndents method when the Classic panel style is used

Static validators emitting "nbsp;"

I have a .NET question. For my particular application which is catoring to mobile devices (specifically blackberry at the moment), I am using validators (required field validator to be exact).
The problem is that I have disabled javascript from asp.net (by specifying ClientTarget="ie4", but setting EnableClientScript="False" on the validator tags has the same effect). The actual issue is that when the validator is invisible, it emits "nbsp;" instead of nothing, is there some way to override this unwanted result?
Please do not reply solutions that include css or javascript, as I am unable to use either in my particular situation.
Thank you.
Display=Static means that a single nonbreaking space ("&nbsp") is emitted. This last behavior exists so that table cells containing only validators do not collapse to nothing when valid.
From here.
As Frédéric Hamidi said, you could try Display=Dynamic instead, but if you're insistent on using Display=Static, I think your only option is to extend the validator and override the Render method.
protected override void Render(HtmlTextWriter writer)
{
if (this.Display == ValidatorDisplay.Static && this.IsValid)
{
writer.Write(String.Empty);
}
else
{
base.Render(writer);
}
}
Static validators will indeed render an entity when hidden.
Try using dynamic validators instead, by setting their Display property to ValidatorDisplay.Dynamic.

Custom ListView to show EmptyDataTemplate and InsertItemTemplate at the same time

It is known that the ListView control can't display both an EmptyDataTemplate and a InsertItemTemplate at the same time.
For my design style I need to be able to show both. I want to be able to show that no data exist and at the same time show a form to add new data.
I've already implemented various solutions, such as putting a PlaceHolder in my LayoutTemplate and then manually showing or hiding this PlaceHolder in the code-behind, depending on if there is data or not.
However, I would like a control that has this built-in capability in order to keep my code-behind light.
I believe there are only two ways to achieve what I want:
First way (preferred) is to write that custom control myself. I was thinking of deriving from ListView and overriding the function responsible for disabling the EmptyDataTemplate, but I have no experience with custom controls. And I'm not even sure it will work in the end.
Second way is to use a custom control found or purchased somewhere. I have not been able to find such control that has the same base capabilities as the ListView.
Has anybody any idea how to solve #1 and maybe #2?
Thank you.
Here is what I ended up doing:
public class MyListView : ListView
{
protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
{
int itemCount = base.CreateChildControls(dataSource, dataBinding);
if (this.InsertItemPosition != InsertItemPosition.None && itemCount == 0)
{
CreateEmptyDataItem();
}
return itemCount;
}
}
Works great!
I would go for your option 1: Create a custom control
Because you haven't specified a programming language I made one in VB.NET:
Public Class CustomListView
Inherits ListView
Public Sub CheckEmptyData() Handles Me.PreRender
If Me.Items.Count = 0 Then
Dim label As New Label
label.Text = "No data found <br/>"
Me.Controls.AddAt(0, label)
End If
End Sub
End Class
Just tested it and works perfectly, it can just replace an existing ListView.
As you can see it checks if there is any data and if not it inserts a label with the text "No data found". I haven't found an easy way to use the EmptyDataTemplate for this, that would be a better option but this might already work for you.
Another option is to hide the InsertItem (InsertItemPosition.None) if there is no data, and add a Button "Insert" to the EmptyDataTemplate that enables the InsertItemTemplate and therefore hides the EmptyDataTemplate.
I don't understand much of your requirement without a screen shot of what you are actually trying to achieve. Anyway, you may be able to achieve this interface with a combination of ListView+FormView or ListView+ a User Control. If you can provide any more info I may help further.

Custom Itemrender in Datagrid with Datatip

I have a datagrid with one datagridcolumn in it. Without a custom itemrenderer I can use a datatipfunction for showing a custom datatip but now I want to have a custom item render for colouring the rows differently. Therefore I extended a label and changed the data method but now my datatipfunction does not work anymore.
Any ideas?
thanks in advance
Sebastian
I know this question is a wee bit old, however I just ran into the same problem and solved it by looking at how the standard DataGridItemRenderer class does it.
So basically I ended up copying that toolTipShowHandler() function into my class (without any modification), implementing the IDropInListItemRenderer interface and adding a few lines into my renderer's commitProperties() function, which were inspired by the DataGridItemRenderer, too.
Hope this helps.
I'm a little late to the party, but I ran into this issue with a custom DataGridItemRenderer for images. The solution described at the following link worked out nicely for me:
http://www.kalengibbons.com/blog/index.php/2008/12/displaying-datatips-when-using-an-itemrenderer/
The gist is that you override the item render's updateDisplayList() and set a tool tip by calling the dataTipFunction and/or using the dataTipField just like a built-in item renderer.
copying the content of link given by cbranch here. stackoverflow is more reliable for keeping code snippets
Displaying DataTips when using an itemRenderer
One of the bad things about using itemRenderers in a DataGridColumn is that you lose the dataTip functionality that it normally provides. Well, here is a way to fake that functionality.
First, add the dataTipField or dataTipFunction to the DataGridColumn like you normally would.
<mx:DataGridColumn headerText="DataTip"
dataField="name1"
showDataTips="true"
dataTipField="description1" />
Then, in your itemRenderer add the following code to be able to tap into that information and display a tooltip instead.
private function getToolTip():String{
var dg:DataGrid = listData.owner as DataGrid;
var func:Function = dg.columns[listData.columnIndex].dataTipFunction;
if(func != null){
return func.call(this, this.data);
}else if(dg.columns[listData.columnIndex].dataTipField.length){
return data[dg.columns[listData.columnIndex].dataTipField];
}else{
return "";
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth, unscaledHeight);
this.toolTip = getToolTip();
}
This works with both dataTipFields and dataTipFunctions and lets you treat the dataTips in your columns the same way, regardless of whether you’re using an itemRenderer or not. The only minor difference is the positioning of the label, but that can be easily modified with styles. You can download the full source code here, for a functional example of how this works.
source
Just off the top of my head, maybe make your custom item renderer extend DataGridColumn. This will give your item renderer all the functionality of a regular column.

Resources