drop in an HBox - flex3

I have this HBox with drop functionality:
SCRIPT:
// The dragEnter event handler for the HBox container enables dropping.
private function dragEnterHandler(event:DragEvent):void
{
if (!event.dragSource.hasFormat("items"))
return;
var dropTarget:Box = Box(event.currentTarget);
dropTarget.setStyle("borderStyle", "outset");
DragManager.acceptDragDrop(dropTarget);
DragManager.showFeedback(DragManager.MOVE);
}
private function dragExitHandler(event:DragEvent):void
{
if (!event.dragSource.hasFormat("items"))
return;
var dropTarget:Box = Box(event.currentTarget);
dropTarget.setStyle("borderStyle", "inset");
}
MXML
<mx:HBox id="invoiceHBox" borderStyle="inset" borderThickness="3"
height="40" width="260"
dragEnter="{dragEnterHandler(event);}"
dragExit="{dragExitHandler(event);}"
dragDrop="{dragDropHandler(event);}">
<mx:VBox>
<mx:Image source="{MailIcon32}" visible="{Boolean(invoiceEmail)}" />
<mx:Label text="{invoiceEmail.name}" styleName="heading4" />
<mx:Text text="{invoiceEmail.description}"
width="100%" selectable="false" />
</mx:VBox>
</mx:HBox>
When the mouse enters the HBox, it works fine. The data can be dropped into the HBox and the function dragDropHandler (a very long function) does its work.
However, when the mouse hovers over the VBox, the drop functionality is lost. Can the VBox container somehow inherit from the HBox? or is there another solution to this problem?
thanks!

You need to disable the mouseChildren property of the HBox and it should work
<mx:HBox id="invoiceHBox" borderStyle="inset" borderThickness="3"
height="40" width="260"
dragEnter="{dragEnterHandler(event);}"
dragExit="{dragExitHandler(event);}"
dragDrop="{dragDropHandler(event);}"
mouseChildren="false" >
<mx:VBox>
<mx:Image source="{MailIcon32}" visible="{Boolean(invoiceEmail)}" />
<mx:Label text="{invoiceEmail.name}" styleName="heading4" />
<mx:Text text="{invoiceEmail.description}"
width="100%" selectable="false" />
</mx:VBox>
</mx:HBox>

Related

Positioning actionbar items on android

I have this code
<template>
<Page>
<ActionBar title="Action Items">
<StackLayout orientation="horizontal">
<Image src="res://icon" width="40" height="40"
verticalAlignment="center" />
<Label text="NativeScript" fontSize="24"
verticalAlignment="center" />
</StackLayout>
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back"
(tap)="onNavBtnTap()">
</NavigationButton>
<ActionItem (tap)="onShare()" ios.systemIcon="9"
ios.position="left" android.systemIcon="ic_menu_share"
android.position="actionBar">
</ActionItem>
<ActionItem (tap)="onDelete()" ios.systemIcon="16"
ios.position="right" text="delete" android.position="popup">
</ActionItem>
</ActionBar>
<ScrollView>
<StackLayout class="home-panel">
<!--Add your page content here-->
<Label textWrap="true" text="Play with NativeScript!"
class="h2 description-label">
{{first}}
</Label>
<Label textWrap="true"
text=" Write code in the editor or drag and drop components to build a NativeScript mobile application."
class="h2 description-label" />
<Label textWrap="true"
text="Scan the QR code with your mobile device and watch the changes sync live while you play with the code."
class="h2 description-label" />
</StackLayout>
</ScrollView>
</Page>
</template>
<script>
export default {
data() {
return {
first: "Once"
};
}
};
</script>
<style scoped>
.home-panel {
vertical-align: center;
font-size: 20;
margin: 15;
}
.description-label {
margin-bottom: 15;
}
</style>
which produces
My question is how come the back button aligned itself left and the others right without explicitly coding left or right?
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back"
(tap)="onNavBtnTap()">
</NavigationButton>
and the other buttons are aligning to the right
<ActionItem (tap)="onShare()" ios.systemIcon="9"
ios.position="left" android.systemIcon="ic_menu_share"
android.position="actionBar">
</ActionItem>
<ActionItem (tap)="onDelete()" ios.systemIcon="16"
ios.position="right" text="delete" android.position="popup">
</ActionItem>
<NavigationButton/> is by default on the left, as it's just calls into the native setNavigationIcon api:
https://developer.android.com/reference/android/widget/Toolbar#setNavigationIcon(android.graphics.drawable.Drawable)
While the other <ActionItem> elements are added with the Menu api:
https://developer.android.com/reference/android/widget/Toolbar#getMenu()
For your other question, you can do the following:
<Label :text="`${first} Play with NativeScript!`" textWrap="true" class="h2 description-label" />
:text makes it a binding, the then you pass in a regular JavaScript string literal.
An alternative would be:
:text="first + ' Play with NativeScript!'"
Both ways should work fine.

How to change open animation of flyout menu

I have a menu flyout which is opened on ListView Items. The default open animation is quite slow is there a way to change the default animation of flyout menu?
EDIT
I am using following dependency property for showing context menu on list view item it works fine but when context menu is shown it squeezes the the whole view a bit. I do not want to squeeze the page when context menu is opened.
public class OpenMenuFlyoutAction:DependencyObject,IAction
{
public object Execute(object sender, object parameter)
{
if (!Global.IsDisabledShowContextMenuOnListView)
{
FrameworkElement senderElement = sender as FrameworkElement;
FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(senderElement);
flyoutBase.ShowAt(senderElement);
}
return null;
}
}
List Item data template
<DataTemplate x:Key="MemberListItemDataTemplate">
<Grid Width="{Binding ElementName=searchView,Path=ActualWidth}" Background="{Binding ItemBackground}"
Margin="0,0,0,20" Height="auto">
<i:Interaction.Behaviors>
<icore:EventTriggerBehavior EventName="Holding">
<helpers:OpenMenuFlyoutAction />
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="share" RequestedTheme="Dark" Command="{Binding ElementName=pageMyProfile, Path=DataContext.ShareMemberDetails}" CommandParameter="{Binding item99}" />
<MenuFlyoutItem Text="reomve from members" RequestedTheme="Dark" Command="{Binding ElementName=pageMyProfile, Path=DataContext.RemoveMember}" CommandParameter="{Binding item99}" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
...
</DataTemplate>
Yeah, you need to create a new Style targeting MenuFlyoutPresenter in your resources
<Style TargetType="MenuFlyoutPresenter">
If you copy it from Program Files (x86)\Windows Phone Kits\8.1\Include\abi\Xaml\Design\generic.xaml you'll notice there are already some storyboards inside for various visual states that you need to change in order to get a different animation.
I wrote about something very similar in my blog post MenuFlyout flip animation on Windows Phone WinRT

Send a boolean as an Action parameter in Caliburn Micro

This is my XAML View (some code omitted for readability):<Window ... xmlns:c="http://www.caliburnproject.org">
<Button Content="Close without saving" c:Message.Attach="Close(false)" />
<Button Content="Save and Close" c:Message.Attach="Close(true)" />
</Window>
And here's the code in the ViewModel:
public void Close(bool save)
{
if (save)
{
// save the data
}
TryClose();
}
This doesn't work - of course - because the action parameters "true" and "false" aren't objects or object properties in the XAML. How can I make this work, and send a boolean as an Action parameter in Caliburn Micro?
If you put single quotes around the parameter name, it will properly convert for you.
<Button Content="Close without saving"
c:Message.Attach="Close('false')" />
<Button Content="Save and Close"
c:Message.Attach="Close('true')" />
You can try to use interactivity + triggers:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cl:ActionMessage MethodName="MyMethod" >
<cl:Parameter Value="True">
</cl:Parameter>
</cl:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>

Flex List Component with Checkbox

I am trying to add a checkbox to a List component in my application and everything works seeming well until I scroll through my data.
As I scroll vertically in my List, any checks I may have added start to get added to other items in my List, sometimes the original item I checked is not even checked anymore.
For example, my List height is enough to see 5 items, I check Item 1, scroll down and every 5th item starts to get checked.
It's really odd and I have not been able to figure out why it is doing this. I looked at some examples online, and I'm not doing anything any different as far as I can tell.
I ran some traces and the Checkbox datachange event fires as I scroll through my list, but again, I am not sure why.
Here is the mxml test page for my List.
Any help is appreciated, thanks.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Array id="arr">
<mx:Object label="One" />
<mx:Object label="Two" />
<mx:Object label="Three" />
<mx:Object label="Four" />
<mx:Object label="Five" />
<mx:Object label="Six" />
<mx:Object label="Seven" />
<mx:Object label="Eight"/>
<mx:Object label="Nine" />
<mx:Object label="Ten" />
<mx:Object label="Eleven" />
<mx:Object label="Twelve" />
</mx:Array>
<mx:List
id="addrList"
height="100"
width="100%" fontSize="10"
borderStyle="solid"
borderColor="#000000"
borderThickness="1"
dataProvider="{ arr }">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox
change="trace('change')"
dataChange="trace('dataChange')"/>
</mx:Component>
</mx:itemRenderer>
</mx:List>
</mx:Application>
your putting an object to a list dataprovider, dataprovider supports text only
try this
<mx:Script>
<![CDATA[
[Bindable]
private var arr:Array = ["a","b","c","d","e","f","g"];
]]>
</mx:Script>
<mx:List
id="addrList"
height="100"
width="100%" fontSize="10"
borderStyle="solid"
borderColor="#000000"
borderThickness="1"
dataProvider="{ arr }">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox change="trace('change')"
dataChange="trace('dataChange')"/>
</mx:Component>
</mx:itemRenderer>
</mx:List>

Creating a column of RadioButtons in Adobe Flex

I am having an un-predictable behavior of creating radio buttons in advancedDataGrid column using itemRenderer. Similar kind of problem has been reported at
Creating a column of RadioButtons in Adobe Flex. I tried to use the same procedure i.e. bind every radio button selectedValue and value attributes with the property specified in the property of the associated bean but still facing the problem.
The button change values! The selected
button becomes deselected, and
unselected ones become selected.
Here is the code of my advancedDataGrid:
<mx:AdvancedDataGrid id="adDataGrid_rptdata"
width="100%" height="100%"
dragEnabled="false" sortableColumns="false"
treeColumn="{action}"
liveScrolling="false"
displayItemsExpanded="true" >
<mx:dataProvider>
<mx:HierarchicalData source="{this.competenceCollection}" childrenField="competenceCriteria"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn headerText="" id="action" dataField="criteriaName" />
<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:RadioButton name="period1" value="{data}" selected="{data.period1}" group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn headerText="Periode 2" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:RadioButton name="period2" value="{data}" selected="{data.period2}" group="{data.radioBtnGrpArray[1]}" visible="{data.showRadioButton}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn headerText="Periode 3" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:RadioButton name="period3" value="{data}" selected="{data.period3}" group="{data.radioBtnGrpArray[2]}" visible="{data.showRadioButton}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
</mx:columns>
</mx:AdvancedDataGrid>
Any work around is highly appreciated in this regard!
The selected button becomes deselected, and unselected ones become selected.
Is this problem occurring only for those radio buttons whose selected state was manually changed by the user? In that case it is because flex resets its selected state based on the value mentioned in the declaration when a RadioButton is reused. So even if you select/deselect a ratio button in the Periode 1 column, flex resets it to {data.period1} when you scroll away and come back. Making the column editable to save the modifications back to the data provider might work. Try changing the column declaration to:
<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200"
editable="true" rendererIsEditor="true" editorDataField="selected">
EDIT: Try this - attempting to change the data provider when the radio button is selected. code written from memory and not tested - might contain bugs.
<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%"
verticalAlign="middle">
<mx:RadioButton id="rb" name="period1" value="{data}"
selected="{data.period1}"
group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}"
change="outerDocument.handleRadio1(this);"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
//in a script tag outside the datagrid.
public function handleRadio1(renderer:IListItemRenderer):void
{
var index:Number = adDataGrid_rptdata.itemRendererToIndex(renderer);
this.competenceCollection[i].period1 = renderer.rb.selected;
}