I have outerstacklayout on button click it generates an inner stacklayout.
This inner stacklayout contains element like Label, combobox and a delete_button.
With delete_button I need to delete specific stacklayout.There can be 100 stacklayout and I can delete any number of stacklayout.This is mine code of delete_method
private void Delete_Clicked(object sender, EventArgs e)
{
stack.Children.Remove(label1); stack.Children.Remove(label2); stack.Children.Remove(label3);
stack.Children.Remove(label4); stack.Children.Remove(border1);stack.Children.Remove(border2);
stack.Children.Remove(border3); stack.Children.Remove(border4);
stack.Children.Remove(button);
//var button = (SfButton)sender;
//var parent = button.Parent;
//OuterStack.Children.Remove(parent);// = (Button)sender;
// stack.Children.Clear();
// OuterStack.Children.Remove(stack1);
//OuterStack.Children.Add(stack1);
}
Right now only a single stacklayout is able to delete if I uncomment all stacklayouts get delete.I want to delete specific ones.
when you create your section, assign a reference to the StackLayout to the Button using the Button's CommandParameter property
StackLayout stack = new StackLayout();
Button delete = new Button { ... };
delete.CommandParameter = stack;
delete.Clicked = DeleteSection;
stack.Children.Add(delete);
in your event handler
protected void DeleteSection(object sender, EventArgs args)
{
Button btn = (Button)sender;
StackLayout stack = (StackLayout)btn.CommandParameter;
// outer is the StackLayout that contains all sections
// stack is the inner StackLayout that contains just one section
outer.Children.Remove(stack);
}
here is a complete example that does this (click to see gif)
If the OuterStack only contains the multi StackLayouts , you just nned to inviked the following line .
protected void DeleteSection(object sender, EventArgs args)
{
OuterStack.Children.RemoveAt(2); // it will remove the third StackLayout in OuterStack
}
Related
I have a page in Xamarin.Forms in which I have to show PKPaymentButton by using the same PKPaymentButton class which is a child of UIButton in PassKit.
I have written a custom ButtonRenderer and trying to convert the button into PKPayment button.
I got so far that in custom renderer we can change the appearance of a button but can we use something like creating a new button instance in my case PKPaymentButton and replace it with Button.
UPDATE-
I have achieved this by-
public class ApplePayButtonRenderer : Xamarin.Forms.Platform.iOS.ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var button = new PKPaymentButton(PKPaymentButtonType.Buy, PKPaymentButtonStyle.Black);
SetNativeControl(button);
}
}
}
Now I am trying to get its click into Xamarin.Forms
You could use Messaging Center to send message when you click the payment Button.
in Custom Renderer
var button = new PKPaymentButton(PKPaymentButtonType.Buy, PKPaymentButtonStyle.Black);
button.TouchUpInside += Button_TouchUpInside;
SetNativeControl(button);
private void Button_TouchUpInside(object sender, EventArgs e)
{
MessagingCenter.Send<Object>(this,"PayButtonClick");
}
in Forms
Add the following code to the constructor of the ContentPage which contains the Payment Button
public xxxPage()
{
InitializeComponent();
MessagingCenter.Subscribe<Object>(this, "PayButtonClick",(args)=> {
//do some thing you want
});
}
I have following problem in javafx tableview, my table view is connected to certain model, and normal CRUD operations work with no issues, I also added a column which is not connected to ANY data model, and it just contains a hyperlink on which user can click, and he is prompted with a pop up.
All of this work, what it does not work is, when I click on hyperlink I want to also pass the row value, and normally it works like
tableview.getSelectionModel().getSelectedItem();
But now it does not work, since i am not clicking directly a cell, but I click a hyperlink, and if I click first some row and then hyperlink, I get that row that I highlighted. Is there any way to select row when clicking hyperlink,so I don't have to first click row then hyperlink in same row.
public class RemoveCell<T> extends TableCell<T, Void> {
private final Hyperlink link;
private final Hyperlink link1;
private final HBox pane = new HBox();
public RemoveCell() {
link = new Hyperlink("Remove");
link1 = new Hyperlink("Edit");
pane.getChildren().addAll(link,link1);
link1.setOnAction(evt -> {
//lagerRet();
if(tableView.getSelectionModel().getSelectedItem()!=null) {
System.out.println("not null");
}
else {
System.out.println("null");
}
// remove row item from tableview
// ap.getChildren().removeAll();
//ap.getChildren().setAll(mcon.loadParent(FxmlView.CHART));
PopOver popsy = new PopOver();
try {
popsy.setContentNode(control.loadUni(FxmlView.POP));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//popsy.setContentNode(panemain);
popsy.headerAlwaysVisibleProperty().set(true);;
popsy.show(link);
});
link.setOnAction(evt -> {
// remove row item from tableview
System.out.println("a quick test");
});
}
#Override
protected void updateItem(Void item, boolean empty) {
super.updateItem(item, empty);
setGraphic(empty ? null : pane );
//setGraphic(empty ? null : link1 );
}
}
and lastly this how I populate column
testColumn.setCellFactory(tc -> new RemoveCell<>());
It's possible to access the row item via TableRow containing the TableCell.
T item = getTableRow().getItem();
It's also possible to get the index in TableView.items using TableCell.getIndex which allows for removal without searching for the item in the list first.
int itemIndex = getIndex();
getTableView().getItems().remove(itemIndex);
I want to display a drop down menu when a user clicks a button. Something like comboBox but instead of the comboBox its a button. How can I do it??
I solved it using PopupMenu. Here is the code for other's reference.
public static Rect GetElementRect(FrameworkElement element)
{
GeneralTransform buttonTransform = element.TransformToVisual(null);
Point point = buttonTransform.TransformPoint(new Point());
return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var menu = new PopupMenu();
menu.Commands.Add(new UICommand("Label", (command) =>
{
//do work
}));
// We don't want to obscure content, so pass in a rectangle representing the sender of the context menu event.
// We registered command callbacks; no need to handle the menu completion event
var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
if (chosenCommand == null) // The command is null if no command was invoked.
{
}
}
Milan,
You'll need to create a custom control or a user control that combines a button and a popup. You could also just implement this in-place with a button and popup. I suggest you look at Callisto's Menu control and start from there to implement your dropdown menu:
Callisto controls (includes a Menu)
I have a parent page Page1 which has button1. Page1 has a usercontrol uc1. uc1 has an update panel inside which a grid grid1 is present. I am trying to set Page1.button1's visibility to false, depending on the row command event(there are some if conditions in the row command event) of uc1.grid1. I am setting Page1.button1's visibility in the following way:
Create a IsButton1Visible property in uc1. Set the property in UC1.Grid1.RowCommand to false, on page1 PreRender event, access IsButton1Visible and set Page1.button1 visibility.
Even though in quick watch Page1.button1 visibility is set to false at the line of assignment, when I see the UI, it is still visible. I don't know what I am doing wrong. Or the way that I am getting hold of button1 and its visibility is not correct.
In general can we set a Parent page's control's property from a user control during the user control event?
If you use the event-driven model approach
Delegate/EventArgs code:
public class ButtonVisiblityEventArgs : EventArgs
{
public ButtonVisiblityEventArgs(bool visible)
{
this.Visiblity = visible;
}
public bool Visiblity { get; private set; }
}
public delegate void UpdateParentButtonVisibilityEventHandler(object sender, ButtonVisiblityEventArgs args);
User control code:
public event UpdateParentButtonVisibilityEventHandler RaiseUpdateParentButtonVisibilityEvent;
private void RequestParentButtonVisibilityChange(bool setVisible)
{
if (RaiseUpdateParentButtonVisibilityEvent != null)
{
RaiseUpdateParentButtonVisibilityEvent(this, new ButtonVisiblityEventArgs(setVisible));
}
}
And in your command handler, just call:
RequestParentButtonVisibilityChange(false);
whenever you want to hide the button. On your page:
protected void Page_Load(object sender, EventArgs e)
{
this.RaiseUpdateParentButtonVisibilityEvent += new UpdateParentButtonVisibilityEventHandler(uc_RaiseUpdatecurrentDisplayPanelRequestEvent);
}
private void uc_RaiseUpdatecurrentDisplayPanelRequestEvent(object sender, ButtonVisiblityEventArgs args)
{
button1.Visible = args.Visiblity;
}
If the problem you are having is that your button lives outside of the update panel, you can do the following. Page codebhind:
protected void Page_Load(object sender, EventArgs e)
{
string hideScript = string.Format("function updateButtonVisibility( visibility ) {{ var button = $('#{0}'); if (visibility) {{ button.show(); }} else {{ button.hide(); }} }}", this.button1.ClientID);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "updateButtonVisibility", hideScript, true);
}
And in your user control command handler:
bool shouldButtonBeVisible = false; //update this appropriately in your logic
ScriptManager.RegisterStartupScript(this, this.GetType(), "upUpdateButtonVisibility", "updateButtonVisibility(" + shouldButtonBeVisible ? "true" : "false" + ");", true);
Please note that this creates a TIGHT dependency between your UC and the page. It requires that any page that consumes this control has registered this script. There are ways to get around this (such as setting a function script callback to call, detecting if that javascript function exists, etc), but this should at least get you moving.
If there is something specific on the page after your update panel finishes that you could key off, it might be better to register an end request handler
$(function() { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(updatePanelEndRequestHandler); } );
function updatePanelEndRequestHandler() {
var shouldBeVisible = $('.MyClassThatSaysIShouldntAllowMoreButtons').length > 0; //do some checking on the grid
updateButtonVisibility(shouldBeVisible);
}
you can put your user controls inside panels on your parent pages and change the visibility.
e.g.
<asp:Panel runat="server" ID="pnlQuote">
...
</asp:Panel>
<asp:Panel runat="server" ID="pnlContact">
<uc1:ContactForm runat="server" ID="ContactForm " />
</asp:Panel>
From the child control you can make a button click event which does something like this
protected void btnBackToQuote_Click(object sender, EventArgs e)
{
Panel pnlQuote = this.Parent.FindControl("pnlQuote") as Panel;
Panel pnlContact = this.Parent.FindControl("pnlContact") as Panel;
pnlQuote .Visible = true;
pnlContact.Visible = false;
}
I have a webpage with filter selects at the top, a search button and a ListView with custom pager (witch is a Repeater witch contains LinkButtons with page numbers) at the bottom.
When I select filters and click the search button, I put the results in a List<> and DataBinding them at ListView. The function witch returns the results has two properties that are StartIndex and PageSize. So when I click a page I call again the function with new PageIndex. Sometimes the results need more columns from the ListView.
So I create two classes (ResultsLayoutTemplate.cs, ResultsItemTemplate.cs) to design the layout for ListView.
The problem is when I select a page (custom pager of ListView) whitch the results need more columns to ListView, the header of table does not change the columns and keeps the previous page header design. Lines have the right columns.
For example in first page ListView has 8 columns and in second page ListView must have 13 columns. But it keeps 8 columns for the header. The same happen when the third page need 8 columns it appears 13 from the previous page. The problem is only on the header.
Here's the code.
protected void ListView1_LayoutCreated(object sender, EventArgs e)
{
results = Session["results"] as List<Res>;
if (results.Count > 0)
{
Session["columns"] = results.Max(i => i.columns.Count);
}
ListView lv = sender as ListView;
ListView1.LayoutTemplate = new ResultsLayoutTemplate((int)Session["columns"]);
ListView1.ItemTemplate = new ResultsItemTemplate((int)Session["columns"]);
ListView1.AlternatingItemTemplate = new AlterResultsItemTemplate((int)Session["columns"]);
Control newlayoutContainer = new Control();
lv.LayoutTemplate = new ResultsLayoutTemplate((int)Session["columns"]);
lv.LayoutTemplate.InstantiateIn(newlayoutContainer);
var usercontrol = newlayoutContainer.Controls[0];
usercontrol.ID = "MyLayout";
lv.Controls.Add(newlayoutContainer);
}
protected void Page_PreRender(object sender, EventArgs e)
{
int num;
bool isNum = Int32.TryParse(Session["page"].ToString(), out num);
if ((Int32.Parse(Session["page"].ToString()) > 0) && (isNum))
{
results = Session["results"] as List<Res>;
Session["platos"] = results.Max(i => i.quadruplette.Count);
ListView1.Items.Clear();
ListView1.ItemTemplate = new ResultsItemTemplate((int)Session["columns"]);
ListView1.AlternatingItemTemplate = new AlterResultsItemTemplate((int)Session["columns"]);
ListView1.DataSource = results;
ListView1.DataBind();
}
}
protected void lbPage_Click(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
int num;
bool isNum = Int32.TryParse(btn.Text, out num);
if (isNum)
{
Session["page"] = btn.Text;
}
results = GetResults(Filters, (Int32.Parse(Session["page"].ToString()) - 1) * PageSize, PageSize);
Session["results"] = results;
Session["columns"] = results.Max(i => i.columns.Count);
}
}
not 100% sure i understand the question, but it sounds like you're trying to reinvent the wheel. Why not use the asp.net pagercontrol and just define the layout to fit what you need. Then use a sqldatasource control with a WHERE clause bound to your filter controls. Then bind that to the listview. Then have the sqldatasource rebind when you click the go button. any special operations that need to be performed before the bind actually happens can happen in the Selecting event.