Propertychanged delegate in BindableProperty is called twice with datatrigger - xamarin.forms

I know that this question was already asked but I was not able to find a solution for my problem.
My question is this: I've a bindable property in a custom control that is exposed to show a text (the pagetitle), and I need that this text is cutted when the view is in portrait.
I want that this bindable property takes its value from a property inherited from a base (PageTitle) and than that a converter do the work to cut the word when it's needed.
I have created a datatrigger to fire that converter, but I think that I misunderstanded how it works, because on the first rotation all works as expected, but from the second rotation the Propertychanged delegate is fired twice and I didn't understand why.
I was able to solve this specific problem using a Label binded to the property that I use as parameter in my converter, but it's not a clean way to achieve the result and I would understand if something is wrong with my datatrigger and what.
I've a created a simple demo project published on git here that explains better what I mean, in the first row I've inserted the control with the bindable property that doesn't work, and in the thirth the solution that works but that it's surely not the best practice to do it.
Thank you in advance

Related

Should children of a ContentPage be rendered too when using a custom renderer?

I’ve been using Xamarin.Forms for a bit lately and can generally get enough information following the Microsoft docs. But I seem to be stuck now that I need to create a custom renderer, so if someone could help, I’d really appreciate.
I read through the docs on creating a custom render and maybe I missed the part I’m looking for, but I’m not able to tell if as part of OnElementChanged, I also need to render all the children of the Element?
The ContentPage could have a StackLayout for example with several child elements. If I dont have to render these, how do they get rendered/laid-out?
No, you don't need to render ContentPage's children.
When you create a Custom Renderer you are only extending Xamarin's renderer, meaning you only add functionality (unless you explicitly change something, like redefining a property).
So, basically, the ContentPage render/lay-out the children the same way it renders/lays-out without the Custom Renderer.
Answering your second question, actually the layout and positioning is done without renderers, as said here Xamarin.Forms Layouts.
If you want to dig deeper, you can try to understand how the ContentView (it's the easier one) is positioned by reading the source code. Here the TemplatedView (ContentView's base class) is calling LayoutChildIntoBoundingRegion for each of its children: TemplatedView.
Then this line on the LayoutChildIntoBoundingRegion calls the Layout method of the view: Layout.
The VisualElement.Layout method only gets the rectangle and sets the Bounds of the view (Layout Method). The Bounds setter is called: Setter.
Well, now you can go on and explore more of the source code if you want, but I think you got the idea ;)
Hope it helps!

What's the NSView version of NSCell's highlighted property?

I'm migrating a cell-based NSTableView to be view-based. With NSCell, to determine if a cell was highlighted (e.g., to draw the text in white instead of black), I looked at the NSCell highlighted property.
What's the NSView version of this? I can't find anything like this in the docs.
The easiest way to do this is to simply subclass NSTableCellView. All the documentation says that you can subclass either NSTableCellView or NSView, e.g., Table View Programming Guide for Mac:
Drag an NSTableCellView object (or a custom view) from the object library to the appropriate column in the table view. ... Typically, the view class is a subclass of NSTableCellView.
It doesn't say what this is, or why you'd want to use it. It looks like an NSView which has an NSTextField and an NSImageView, and that's it -- so if you're not making a view that has these, it's tempting to ignore this class and just subclass NSView.
Interestingly, though, if you have any NSTextFields in an NSTableCellView (even if you don't use the textField property for this!), they automatically use the correct light/dark coloring.
In particular, it seems that the backgroundStyle property of NSTableCellView is what causes the text value to actually change. The documentation says:
The default implementation automatically forwards calls to all subviews that implement setBackgroundStyle: or are an NSControl, which have NSCell classes that respond to setBackgroundStyle:.
NSTextField is an NSControl with an NSCell, of course, so it gets this called on it.
While it's not exactly clear in Apple's documentation (what does "this" refer to?), it seems that NSTableView calls -setBackgroundStyle: on any view that defines it. So if you don't want to subclass NSTableCellView, you can alternatively just add a property to your own NSView:
var backgroundStyle: NSBackgroundStyle
and have your drawing code use that.

Flex: Using custom LineSeries so that item rendering/data tip still works

Brief description: If I create a customized LineSeries class and add that one to my project, even if it's the same as original, I lose data tip functionality.
Elaborated description:
I'm using a LineChart component and I needed to render my lines so that they change color according to some value ranges. So I modified LineRenderer, applied it to my LineSeries and everything was working great. Unfortunately I later realized that I will need to supply ranges and colors dynamically as they're supposed to be customizable. This is where it gets tricky.
This is the code I use to set my lineRenderer:
var cf:ClassFactory = new ClassFactory(myLineRenderer);
lineSeries.setStyle("lineSegmentRenderer",cf);
I did not find a way to dynamically change data on a ClassFactory without making an instance of it. But if I make an instance of it, I can not set it as a style. If anyone knows of a way to do this, it would solve my problem straight out. All I need is to set an array property inside myLineRenderer. But it makes sense to me why this can't be done.
Can I dynamically make a new Class that is a clone of myLineRederer yet has one property changed?
Can I add an argument to myLineRenderer constructor? If so, how would that work with the code above?
Anyway, since that didn't work, I figured I needed to change the data supplied to myLineRenderer. For this I created my own LineSeries that has a settable Array property that it adds to the data passed to myLineRenderer. And it works great. With one little kink. As soon as I change my LineChart series from LineSeries to myLineSeries, I can't move the mouse cursor along the line and get info on each item in the chart. I removed all the changes I made to original LineSeries, but it makes no difference. What am I missing?
Right now I'm trapped between having customizable color ranges with no data tips and non-customizable color ranges with data tips. The former is still better, but I would really need both to work or at least know why that's impossible.
Any help would be much appreciated.
Take a look at the properties property of ClassFactory
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/ClassFactory.html#properties
I think that does exactly what you need it to.

Expression Blend, Button states, how to?

Sorry for such a rudimentary question, but I am not experienced in Blend 4 much at all.
What I need to do, and based on the little I know or have seen it seems that Blend is the place to do it, is to create a "state" for a button to appear when it is disabled. i.e., the button I'm working with is a Sign Out button...the button IsEnabled property is bound to the WebContext.User.IsAuthenticated property. So, when the app is loading I want the button's "disabled state (<-- created in Blend?) to appear...once authentication is completed, the binding to IsEnabled will change, and I want the button's "enabled state" to kick in. How to accomplish this? Thanks in advance.
Your problem looks extremely similar to an issue I was having the other day.
If you go to this thread you may be able to use that as a solution: Expression Blend Interaction: How to set Trigger to Look for IsEnabled Value of Button?
I have a Boolean value there called "IsSavedAllowedBool". You would want to replace that with whatever bool you are binding to - which looks as if it might be WebContext.User.IsAuthenticated.

How do I tell Qt to always show an editor in a QTableView?

I've got a QTableView for which I want to display the last column always in edit mode. (It's a QComboBox where the user should be able to always change the value.)
I think I've seen the solution in the Qt documentation, but I can't find it anymore. Is there a simple way of doing it?
I think I could archive this effect by using openPersistentEditor() for every cell, but I'm looking for a better way. (Like specifying it only one time for the whole column.)
One way to get the automatic editing behaviour is to call the view's setEditTriggers() function with the QAbstractItemView::AllEditTriggers value.
To display the contents of a given column in a certain way, take a look at QAbstractItemView::setItemDelegateForColumn(). This will let you specify a custom delegate just for those items that need it. However, it won't automatically create an editor widget for each of them (there could in principle be thousands of them), but you could use the delegate to render each item in a way that makes it look like an editor widget.
There are two possibilities:
Using setIndexWidget, but Trolltech writes:
This function should only be used to
display static content within the
visible area corresponding to an item
of data. If you want to display custom
dynamic content or implement a custom
editor widget, subclass QItemDelegate
instead.
(And it breaks the Model/View pattern…)
Or using a delegate's paint method. But here you have to implement everything like enabled/disabled elements yourself.
The QAbstractItemModel::flags virtual function is called to test if an item is editable (see Qt::ItemIsEditable). Take a look at Making the Model Editable in the Model/View Programming documentation.
I can't see an easy way to do this, but you might be able to manage by using a delegate. I honestly don't know exactly how it would work, but you should be able to get something working if you try hard enough. If you get a proper delegate, you should be able to set it on a whole view, one cell of a view, or just a column or row.

Resources