I have a very common problem, but I couldn't find any valid solution.
I want to create a Button able to contain more than a simple Label or Image. In fact, Xamarin Button exposes only Text and Image properties, but in my case I want to construct a more flexible set of controls (e.g. a StackPanel with a list of controls).
I implemented a ContentView acting as a Button after having added TapGestureRecognizer and it works from the pure functional point of view. What I don't like is the missing of all Visual States of a Button.
Therefore, I was thinking how to implement a Custom Renderer of a Button. I would like to expose a ContentPresenter BindableProperty and then set that property to the Button.Content (speaking in UWP terms) in the Renderer class. I think this could be a solution, the problem is that I don't know how to "cast" a Xamarin.ContentPresenter to a UWP.ContentPresenter. Do you have any idea about how to implement a Button able to contain any generic Content?
Related
I have a Xamarin forms application. It has a page. That page has a listview. The listviews is bind to a sourcelist. What I want is to decide what custom control to use based on a specific property that each item in the list has. How can I achieve this?
It is also required that the custom control binds to values from the list.
I tried the following:
<ContentView Content="{Binding IsPriority, Converter={StaticResource RoadIndicatorBackgroundValueConverter}}" ControlText="{Binding TowingOrder.Location.RoadIndicator}"></ContentView>
That won't work because I can't bind with the ControlText of the specific custom control.
The image above shows the problem. The A1, A50 and the blue icons are all custom controls, those aren't images. There are some more of these custom controls. I can't just make 10 datatemplates right and copy paste everything? That would be so much duplicate code. Can't I just use a base object in a datatemplate, and bind a property with a converter and use a switch/case to decide which custom control to return?
It is not a good design to binding the content of whole layout in runtime.
From the screen shot , it seems that each cell are similar .So you could create a base Custom Control and define all controls in advance and binding the propertyIsVisible in code behind . Then set its value to control which element should been displayed .
If there are do many dig differences between the cells , use DataTemplateSelector is better .
I have been trying to find the button that DatePicker and ComboBox uses. I have searched through ComboBoxBase, and all other similar classes, and have been unable to find it. Is there a public version of this?
There is no ComboBoxButton class or public method that creates such a thing. You can try to reproduce what's done in the specific controls by referring to the source code.
The look of the JavaFX controls are defined in their skin classes; so ComboBoxBaseSkin for ComboBox, with some supporting classes for the popup and list view that's displayed inside the popup. For the most part, the skin class defines the layout and behavior (i.e. response to user input), and the actual look (shape of the arrow, colors, etc) is defined by the CSS file.
These buttons are defined in a pretty non-trivial way; for ComboBox the arrow itself is defined as a Region, which is placed inside the arrowButton, which is a StackPane. Then the CSS file defines the shape of the arrow and different colors and borders depending on whether it's pressed, selected, etc.
The source for JavaFX is available via OpenJFX:
Home
ComboBoxBaseSkin
modena.css
In the CSS file, I would search for combo-box (there's a couple of dozen occurrences), and pay particular attention to the .arrow-button and .arrow classes.
We have developed a number of custom JavaFX controls which we build into a JAR and then allow our clients (internal and external) to load into SceneBuilder and then create UI's with those controls. We would like to attach custom property editors to some properties on these controls.
As a made up example, say we have a GraphControl that displays line graphs. It has multiple properties, one of which is "TickStyle", an enum with options DOT, CROSS, CIRCLE, BIG_TICK_STYLE, SMALL_TICK_STYLE, etc.
Now, when I insert this control into SceneBuilder (as a JAR), I can drop instances onto the design canvas. Cool. But I don't want a boring combo-box of tick style values (the enum's toString) e.g. "BIG_TICK_STYLE", but a pretty picker with graphical representations.
The JavaBean spec has the PropertyEditor interface and the BeanInfo thing which does the same thing for Swing. Does this work for JavaFx and how? If it doesn't work for JavaFX, then is there an alternative?
We really don't want to go down the route of hacking SceneBuilder, we just don't have time or people for that.
Thanks!
UPDATE 1
SceneBuilder seems to have its own complex property editors, e.g. for colours. We need editors for
more complex property types (to any level of complexity) such as the Insets editor
more complex editors, such as the colour editor
In Xamarin Forms, I have a custom view with a BindableProperty:
public static readonly BindableProperty SelectedItemProperty
= BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(OneOfNButtons), null,
BindingMode.TwoWay);
I use that custom view within a custom page:
<exodus:OneOfNButtons ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab, Mode=TwoWay}"/>
The two-way binding works as expected.
Now I want to trigger an animation that moves the entire OneOfNButtons control up to middle of page, so I can show related content below it, whenever SelectedItem changes. That is, it is not the primary focus of the page, it is down at bottom. If user is interested in it, they click any of the buttons on it, and half the page becomes dedicated to that topic, with the row of buttons acting like tabs, just above the content.
I understand DataTriggers, but those are for specific values. I'm looking for a trigger on any change to SelectedItem property. (If the logic belonged within the custom control itself, I could add code to the SelectedItem setter.)
This is logic specific to the page, so it belongs with the page; is not part of the custom control.
This is logic specific to this UI, so it belongs with the page, not with page's view model.
I've written the question as "invoke a code behind method", because that is the technique I would like to know how to do in general, even if this specific situation could be handled entirely in XAML.
Though I would also be glad to know how to trigger other XAML, on any change.
(If you know a WPF XAML technique, it might work in Xamarin Forms, though XAML here is more limited. Specifically, X-Forms bound properties are not "DependencyProperty"s, so I don't know how to "chain" properties.)
There are a number of XAML & data binding questions on SO, but all the ones I have found either discuss binding between view and model, or within a single view (I need a change in one view to affect the containing view), or involve messaging between the views (the sub-view does not and should not know about this requirement, so messaging isn't applicable), or triggering on specific values, or are for WPF and don't appear to be supported in Xamarin Forms.
You can handle any property changed events with this.
this.YourControl.PropertyChanged += YourControlPropertyChanged;
private void YourControlPropertyChanged(object sender,PropertyChangedEventArgs e)
{
if(e.PropertyName == "SelectedItem")
{
//Code
}
}
I'm developing a dynamic ItemRenderer to edition in line for Spark DataGrid.
With the Click event on Edit button (first column), I'm refreshing the cell's row using grid.invalidateCell(x,y); inside this custom ItemRenderer, in the function prepare, I'm evaluating an 'editing' dynamic property to hide/show (.visible/.includeInLayout) the default Label or Control for edition; I'm not using actually the itemEditor DataGrid's operation, just simulating this functionality.
Everything goes well with standard spark components for edition: TextInput, ComboBox, etc, but custom components (extended from SkinnableContainer) doesn't get visible, just randomically on first row sometimes.
Is there any specific interface that custom components must implement to work inside an ItemRenderer??
The problem was this property: customComponent.includeInLayout; once you set it to false, it has problems to get visible again. I think it's bad idea to use includeInLayout inside an ItemRenderer.
Now I'm working only with .visible=(false/true) and .x coordinate.
Thanks.