I am trying to use two converters together in my code. One is custom, the other one is the built-in converter.
My goal is to use my converter-modified value as a parameter in another MvvmCross converter.
So, I want to get System.Drawing.Color() first via DueDateTintValueConverter, then I will give it to MvvmCross' "NativeColor" converter.
And finally, the custom binder named TintColor will handle the setting of the Android coloring.
<ImageView
android:id="#+id/imageViewWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:tint="?attr/color_dueDate_normal"
app:MvxBind="TintColor NativeColor(DueDate), Converter=DueDateTint"
app:srcCompat="#drawable/ic_clock" />
But, I run into a binding error here getting "InvalidCastException, nullable DateTime cannot cast to Color".
It means DueDate remains the same regardless of the DueDateTintConverter.
How can I find a solution for this scenario?
Thanks!
Related
Xamarin team introduced 2 different way of stand-alone-resource-dictionaries. Obviously there is a big difference but they neglected to write in their documentation.
Basically if i use without cs code behind file and without x:class defined as defined in the documentation and referencing like that in my page
<ResourceDictionary Source="GradientStyles.xaml"/>
GradientStyles.xaml look like below and i am updating GradientStartColor , GradientStopColor of PancakeView on runtime based on the theme selected.
<pancakeView:GradientStopCollection x:Key="BackgroundGradientStops">
<pancakeView:GradientStop Color="{StaticResource GradientStartColor}"
Offset="0"/>
<pancakeView:GradientStop Color="{StaticResource GradientStopColor}"
Offset="0.74"/>
</pancakeView:GradientStopCollection>
Implementation above just not working. It doesn't update Colors at all.
The same exact code;
Works in ContentPage.Resources directly. It will update
Works if i define a stand-alone-resource-dictionary with cs code behind file and implement on the page like this below
<ResourceDictionary.MergedDictionaries>
<resDics:GradientStyles />
</ResourceDictionary.MergedDictionaries>
There is that annotation in the documentation but i don't get what exactly it means.
This syntax doesnot instantiate the MyResourceDictionary class.
Instead, it references the XAML file.
Does it mean that it extends the contentpage using like partial class or inherits. Or is it cached only once and remains static? And when you use it with code behind class, it creates a new instance every time?
Finally is that a bug or feature? :)
The majority of my activities make an async call to an API as they open to retrieve the data which will be displayed. With ProgressDialog, I can simply pass the context of the activity to my AsyncTask class and display/hide the loading circle as this happens. This is useful as it requires no extra work when adding a new activity that will make an async call.
E.g in onPreExecute():
progressDialog = new ProgressDialog(contextRef.get());
progressDialog.setMessage("Please wait...");
progressDialog.show();
I'd like to make the switch to ProgressBar however this requires adding a ProgressBar to the XML of every activity that will require one. The best i've come up with is copy/pasting the XML to every activity and doing something like this in onPreExecute():
progressBar = ((Activity) contextRef.get()).findViewById(R.id.loading);
progressBar.setVisibility(View.VISIBLE);
This works fine however the ProgressBar is a relatively big chunk of XML:
<ProgressBar
android:id="#+id/loading"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#80000000"
android:indeterminateDrawable="#drawable/loading"
android:translationZ="2dp"
android:clickable="false"
android:paddingTop="250dp"
android:paddingBottom="250dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I'm not a fan of this as if I need to change something I would have to change it everywhere. Is there a way to put the ProgressBar in a layout file and have the other layouts reference this? Or just a better way to go about this in general?
Cheers
I use this library: https://github.com/FANMixco/spots-dialog
private SpotsDialog progressDialog;
and
progressDialog = (SpotsDialog) new SpotsDialog.Builder().setContext(activity)
.setMessage("One moment please ...")
.setCancelable(true)
.build();
progressDialog.show();
I also use it in asynctask, it's easy to swap for progressdialog and works great.
When you use proguard do not forget
-keep class dmax.dialog.** { *;}
Otherwise the points are not displayed
I'm having a few problems creating an integer attribute.
So, as background. I have got a custom canvas view. I have already successfully created a custom string attribute on that. The axml looks like this:
<turbineApp.droid.infrastructure.customViews.TurbineMapCanvas
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/VicMapCanvas"
custom:mapName="VIC"
/>
And the attribute comes from attrs.xml:
<resources>
<declare-styleable name="CustomCanvasView">
<attr name="mapName" format="string" />
</declare-styleable>
</resources>
I was hoping to add an integer attribute. So, I added the following as an element in attrs.xml:
<attr name="originY" format="integer" />
But now the project won't build. At all. With a fail message that the Resources class never got built.
I've unblocked myself by just making it a string and parsing the string in the code. But why will an integer not work? Have the good people at Xamarin not implemented that yet?
Thanks
According to the documentation it is possible to:
In the XML markup, add the if attribute to an element and assign it to the property passed to the createController() method. Prefix the property name with the $.args namespace. Based on the property passed to the method, the application displays a different label.
So this means that if I put:
<Label if="Alloy.Globals.property" color="blue">Foobar</Label
Wont work?? Right now I´m not using the createController method, because it is added on the XML by a Require tag. Is there any way to do this?
As you can see in the docs there are some examples.
One of which:
<Alloy>
<Window>
<Label if="$.args.fooBar" color="blue">Foobar</Label>
<Label if="$.args.fooBaz" color="red">Foobaz</Label>
</Window>
</Alloy>
So yes, this will just work. As long as the property you provide is already set when rendering. Once your variable changes while the view is open it won't update it. For that you'll need data binding
is there any way to bind in layout directly to custom fragment?
ie:
<fragment android:id="#+id/AwesomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxBind="CustomTarget PropertyInVM;" class="My.Awesome.Fragment" />
CustomTarget is CustomTargetBinding
So how you can do this:
create custom control with properties you need
create target bindings
place custom control into layout instead of your fragment
bind from layout