I have a button in ListView which shows and hides based on the button press in ActionBar.
The button is in GetView function like this
ImageButton btnDel = view.FindViewById<ImageButton>(Resource.Id.btn_row_del);
if(_isEdit)
{
if(btnDel.Visibility == ViewStates.Gone)
{
btnDel.Animate().TranslationX(0).SetDuration(2000);
}
}
else
{
if (btnDel.Visibility == ViewStates.Visible)
{
btnDel.Animate().TranslationX(btnDel.Width).SetDuration(2000);
}
}
But the animation doesn't seem to be working.
How can I animate a button inside of a list view.
You might set the button gone or visible immediately when you press your action bar.
You need to set the button gone or visible when animation end by adding the following call back listener:
private void Bt2_Click(object sender, System.EventArgs e)
{
if (bt1.Visibility == ViewStates.Visible)
{
AlphaAnimation disappearAnimation = new AlphaAnimation(1, 0);
disappearAnimation.Duration = 2000;
bt1.StartAnimation(disappearAnimation);
disappearAnimation.AnimationStart += DisappearAnimation_AnimationStart;
disappearAnimation.AnimationEnd += DisappearAnimation_AnimationEnd;
}
else
{
AlphaAnimation disappearAnimation = new AlphaAnimation(0, 1);
disappearAnimation.Duration = 2000;
bt1.StartAnimation(disappearAnimation);
disappearAnimation.AnimationStart += DisappearAnimation_AnimationStart;
disappearAnimation.AnimationEnd += DisappearAnimation_AnimationEnd;
}
}
private void DisappearAnimation_AnimationStart(object sender, Animation.AnimationStartEventArgs e)
{
if (bt1.Visibility == ViewStates.Visible)
{
bt1.Animate().TranslationX(bt1.Width).SetDuration(2000);
}
else
{
bt1.Animate().TranslationX(0).SetDuration(2000);
}
}
private void DisappearAnimation_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
{
if (bt1.Visibility == ViewStates.Visible)
{
bt1.Visibility = ViewStates.Invisible;
}
else
{
bt1.Visibility = ViewStates.Visible;
}
}
screen shot:
Add a Start() to your animation:
btnDel.Animate().TranslationX(btnDel.Width).SetDuration(2000).Start();
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a pictureBox that I use as a button. When I start the form I load it as disabled and after pressing a button I activate it, it works to change the image from disabled to activated. Then, when I disable this pictureBox again, the image doesn't change anymore ... what could be wrong?
here's my code:
private void btnUpdate_EnabledChanged(object sender, EventArgs e)
{
if (btnUpdate.Enabled == true)
{
if (mt.ArquivoExiste(Metodos.pathImagens, botaoUpdateNormal))
{
Image bt = Image.FromFile(Metodos.pathImagens + botaoUpdateNormal);
btnUpdate.BackgroundImage = bt;
}
}
else
{
if (mt.ArquivoExiste(Metodos.pathImagens, botaoUpdateDisabled))
{
Image bt = Image.FromFile(Metodos.pathImagens + botaoUpdateDisabled);
btnUpdate.BackgroundImage = bt;
}
}
}
Edit:
I changed the string to make that easier and put the entire relationated code:
string botaoUpdateNormal = "btnUpdate_normal.png", botaoUpdateDisabled = "btnUpdate_disabled.png",
botaoUpdateFocus = "btnUpdate_focus.png", botaoSearchNormal = "btnSearch_normal.png",
botaoSearchFocus = "btnSearch_focus.png", botaoInsertNormal = "btnInsert_normal.png",
botaoInsertFocus = "btnInsert_focus.png";
then i load the form:
private void IEstoque_Load(object sender, EventArgs e)
{
if (mt.ArquivoExiste(Metodos.pathImagens, botaoUpdateDisabled))
{
Image bt = Image.FromFile(Metodos.pathImagens + botaoUpdateDisabled);
btnUpdate.BackgroundImage = bt;
}
}
After that I have an event that when I change the row of a grid, the btnUpdate activates, and when I click on it and update my dataBase it desactivates.
This code work for pictureBox "like button" and with separate button:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.pictureBox.Enabled = false;
this.pictureBox.EnabledChanged += new System.EventHandler(this.pictureBox_EnabledChanged);
this.pictureBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseClick);
this.button.Click += new System.EventHandler(this.button_Click);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseClick);
}
private void pictureBox_EnabledChanged(object sender, EventArgs e)
{
if (pictureBox.Enabled == true)
{
var botao = "1.png";
Image bt = Image.FromFile(botao);
pictureBox.BackgroundImage = bt;
}
else
{
var botao = "2.png";
Image bt = Image.FromFile(botao);
pictureBox.BackgroundImage = bt;
}
}
private void button_Click(object sender, EventArgs e)
{
pictureBox.Enabled = !pictureBox.Enabled;
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (!MouseIsPicture(e.Location)) return;
TogglePicture();
}
private void pictureBox_MouseClick(object sender, MouseEventArgs e)
{
TogglePicture();
}
private bool MouseIsPicture(Point location)
{
// Make sure the location is over the image.
if (location.X < 0) return false;
if (location.Y < 0) return false;
if (location.X >= pictureBox.Width) return false;
if (location.Y >= pictureBox.Height) return false;
return true;
}
void TogglePicture()
{
pictureBox.Enabled = !pictureBox.Enabled;
}
}
More over: check if pictures you are loading are not the same
I solve it! before deactivating the button I called a form as follows: formname.Show ();
I just changed it to formname.ShowDialog (); and it worked normally.
How can I fix the previous button to move backward in dataGridView row?
The next button is working.
It does nothing.
I don't know how to fix that. Any ideas? I would appreciate it.
Here is my code:
int nRow;
private void Form1_Load
{
nRow = DataGridView2.CurrentCell.RowIndex;
}
private void PreviousData_Click
{
if (row>=0)
{
if (row!=0)
{
DataGridView2.Rows[row].Selected = false;
DataGridView2.Rows[--row].Selected = true;
}
else
{
MessageBox.Show("Need More Data!");
}
}
}
int row;
private void DataGridView2_CellClick
{
if (DataGridView2.SelectedRows.Count != -1)
{
row = DataGridView2.CurrentRow.Index;
}
}
Bind the following two events to your previous and next buttons, respectively and it will do the job.
private void PreviousData_Click(object sender, EventArgs e)
{
var currentRow = DataGridView2.CurrentCell.RowIndex;
if (currentRow == 0)
return;
else
currentRow--;
DataGridView2.ClearSelection();
DataGridView2.CurrentCell = DataGridView2.Rows[currentRow].Cells[0];
DataGridView2.Rows[currentRow].Selected = true;
}
private void NextData_Click(object sender, EventArgs e)
{
var currentRow = DataGridView2.CurrentCell.RowIndex;
if (currentRow == DataGridView2.RowCount - 1)
return;
else
currentRow++;
DataGridView2.ClearSelection();
DataGridView2.CurrentCell = DataGridView2.Rows[currentRow].Cells[0];
DataGridView2.Rows[currentRow].Selected = true;
}
is there any way to get swipe gesture same as windows phone 8 with wptoolkit.
Because wptoolkit nuget package is not available for uwp, so i am unable to get similar swipe gesture on UWP
In windows Phone 8 with the help of WPtoolkit nugetget package
i placed this
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="OnSwipe"/>
</toolkit:GestureService.GestureListener>
over text block, so i can swipe left to right or right to left over textbox1.
and swipe gesture help me to implement this
private static int i;
private void OnSwipe(object sender, FlickGestureEventArgs e)
{
if (e.HorizontalVelocity < 0)
{
i++;
txtBox1.Text = i.ToString();
}
if (e.HorizontalVelocity > 0)
{
i--;
txtBox1.Text = i.ToString();
}
}
i tried Manupulation method with scrollViewer on uwp but it continuously increase the value untill it scroll viewer stopped
and this is codes
private static int i;
private Point initialpoint;
private void scrollview_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
initialpoint = e.Position;
}
private void scrollview_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (e.IsInertial)
{
Point currentpoint = e.Position;
if (currentpoint.X - initialpoint.X >= 2)
{
i++;
txtBox1.Text = i.ToString();
}
if (currentpoint.Y - initialpoint.Y >= 2)
{
i--;
txtBox1.Text = i.ToString();
}
}
}
Any other way to implement same functionality.
Actually you don't need to handle ManipulationStarted in this case and you don't need the initialPoint property. Assuming you have already defined your ScrollViewer's ManipulationMode to the following
ManipulationMode="TranslateX,TranslateInertia,System"
Then you simply use e.Cumulative.Translation.X to tell how long you have swiped in total
private void scrollview_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
if (e.IsInertial)
{
var swipedDistance = e.Cumulative.Translation.X;
if (Math.Abs(swipedDistance) <= 2) return;
if (swipedDistance > 0)
{
i++;
}
else
{
i--;
}
txtBox1.Text = i.ToString();
}
}
Update
Now that I understand your question better, I think you should handle gesture manipulation on the TextBox itself. If you want instant feedback, simply subscribe to the ManipulationDelta event and create a flag to only run the swipe logic once per touch.
private bool _isSwiped;
private void txtBox1_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (e.IsInertial && !_isSwiped)
{
var swipedDistance = e.Cumulative.Translation.X;
if (Math.Abs(swipedDistance) <= 2) return;
if (swipedDistance > 0)
{
i++;
}
else
{
i--;
}
txtBox1.Text = i.ToString();
_isSwiped = true;
}
}
private void txtBox1_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
_isSwiped = false;
}
Make sure you move all the handlers and set the ManipulationMode onto the TextBox.
<TextBox x:Name="txtBox1"
ManipulationMode="TranslateX,TranslateInertia,System"
ManipulationDelta="txtBox1_ManipulationDelta"
ManipulationCompleted="txtBox1_ManipulationCompleted" />
I have a CheckedListBox with 10 items. On each item check a method is being called. I want to disable the checkbox of that particular item for which the method is being executed so that user cannot uncheck the item till the job is completed.
Note: Unchecking of an item calls another method.
Here is the code of ItemCheck Event:
private void host_listbox_ItemCheck(object sender, ItemCheckEventArgs e)
{
int index = e.Index;
try
{
string sitem = host_listbox.Items[index].ToString();
host_list[sitem].checked_event=e;
if (!host_list[sitem].is_busy)
{
host_config.listEnabled = false;
host_list[sitem].con_worker.RunWorkerAsync();
}
if (host_listbox.GetItemCheckState(index) == CheckState.Checked)
{
host_list[sitem].connected = false;
}
}
catch(Exception ex)
{
output_textbox.AppendText("connection failed!" +ex.ToString() +Environment.NewLine);
}
}
You can check/uncheck items in your checkedListBox with this code
checkedListBox.SetItemChecked(item, true);
for more informations go to microsoft documentation
private void host_listbox_ItemCheck(object sender, ItemCheckEventArgs e)
{
int index = e.Index;
try
{
string sitem = host_listbox.Items[index].ToString();
if (host_list[sitem].is_busy // or whatever indicates that background worker is running or any condition that specifies, that you do not want to let this item to be changed)
e.NewValue = e.CurrentValue; //Change the value back
else
{
//Let the checked state of the item change
This code prevent checked state change if associated background work is running:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
workerList = new List<BackgroundWorker>();
for (int i = 0; i < 10; i++)
{
var el = new BackgroundWorker();
el.DoWork += (s, e) =>
{
Thread.Sleep(5000);
};
workerList.Add(el);
checkedListBox1.Items.Add("el " + i);
}
}
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
var worker = workerList[e.Index];
if (worker.IsBusy)
{
e.NewValue = e.CurrentValue;
return;
}
if (e.NewValue == CheckState.Checked)
worker.RunWorkerAsync();
}
public List<BackgroundWorker> workerList { get; set; }
}
Think, that only funcion solution is set selection mode
CheckedListBox.SelectionMode = SelectionMode.None;
private void ItemCheck(object sender, ItemCheckEventArgs e)
{
if (busy)
e.NewValue = e.CurrentValue;
}
I can catch a single-click on a TextBlock like this:
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("you single-clicked");
}
I can catch a double-click on a TextBlock like this:
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
if (e.ClickCount == 2)
{
MessageBox.Show("you double-clicked");
}
}
}
But how do I catch them both on a single TextBlock and differentiate between the two?
You need to fire the event after the click sequence is over... when is that? I suggest using a timer. The MouseDown event would reset it and increase the click count. When timer interval elapses it makes the call to evaluate the click count.
private System.Timers.Timer ClickTimer;
private int ClickCounter;
public MyView()
{
ClickTimer = new Timer(300);
ClickTimer.Elapsed += new ElapsedEventHandler(EvaluateClicks);
InitializeComponent();
}
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
ClickTimer.Stop();
ClickCounter++;
ClickTimer.Start();
}
private void EvaluateClicks(object source, ElapsedEventArgs e)
{
ClickTimer.Stop();
// Evaluate ClickCounter here
ClickCounter = 0;
}
Cheers!
If you need to detect the difference, I suggest you use a control such as Label that does the work for you:
label.MouseDown += delegate(object sender, MouseEventArgs e)
{
if (e.ClickCount == 1)
{
// single click
}
};
label.MouseDoubleClick += delegate
{
// double click
};
EDIT: My advice was following from documentation on MSDN:
The Control class defines the
PreviewMouseDoubleClick and
MouseDoubleClick events, but not
corresponding single-click events. To
see if the user has clicked the
control once, handle the MouseDown
event (or one of its counterparts) and
check whether the ClickCount property
value is 1.
However, doing so will give you a single click notification even if the user single clicks.
You must use a timer to differentiate between the two. Add a timer to your form in the GUI (easiest that way - it will automatically handle disposing etc...). In my example, the timer is called clickTimer.
private bool mSingleClick;
private void TextBlock_MouseUp(object sender, MouseButtonEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.ClickCount < 2)
{
mSingleClick = true;
clickTimer.Interval = System.Windows.Forms.SystemInformation.DoubleClickTime;
clickTimer.Start();
}
else if (e.ClickCount == 2)
{
clickTimer.Stop();
mSingleClick = false;
MessageBox.Show("you double-clicked");
}
}
}
private void clickTimer_Tick(object sender, EventArgs e)
{
if (mSingleClick)
{
clickTimer.Stop();
mSingleClick = false;
MessageBox.Show("you single-clicked");
}
}
I did it this Way and it works perfectly
If e.Clicks = 2 Then
doubleClickTimer.Stop()
ElseIf e.Clicks = 1 Then
doubleClickTimer.Enabled = True
doubleClickTimer.Interval = 1000
doubleClickTimer.Start()
End If
Private Sub doubleClickTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles doubleClickTimer.Tick
OpenWebPage("abc")
doubleClickTimer.Stop()
End Sub
You are simply can use MouseDown event and count click number, like this:
if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
{
// your code here
}
My suggestion, implemented in a UserControl by simply using a Task:
private int _clickCount = 0;
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
_clickCount = e.ClickCount;
}
protected override async void OnPreviewMouseUp(MouseButtonEventArgs e)
{
if (_clickCount > 1)
{
//apparently a second mouse down event has fired => this must be the second mouse up event
//no need to start another task
//the first mouse up event will be handled after the task below
return;
}
await Task.Delay(500);
if (_clickCount == 1)
{
//single click
}
else
{
//double (or more) click
}
}
The drawback of all these solutions is, of course, that there will be a delay before actually responding to the user's action.
You could do it on MouseUp instead of MouseDown. That way you can ask the ClickCount property for the total number of clicks, and decide what to do from that point.
It's my working solution :)
#region message label click --------------------------------------------------------------------------
private Timer messageLabelClickTimer = null;
private void messageLabel_MouseUp(object sender, MouseButtonEventArgs e)
{
Debug.Print(e.ChangedButton.ToString() + " / Left:" + e.LeftButton.ToString() + " Right:" + e.RightButton.ToString() + " click: " + e.ClickCount.ToString());
// in MouseUp (e.ClickCount == 2) don't work!! Always 1 comes.
// in MouseDown is set e.ClickCount succesfully (but I don't know should I fire one clicked event or wait second click)
if (e.ChangedButton == MouseButton.Left)
{
if (messageLabelClickTimer == null)
{
messageLabelClickTimer = new Timer();
messageLabelClickTimer.Interval = 300;
messageLabelClickTimer.Elapsed += new ElapsedEventHandler(messageLabelClickTimer_Tick);
}
if (! messageLabelClickTimer.Enabled)
{ // Equal: (e.ClickCount == 1)
messageLabelClickTimer.Start();
}
else
{ // Equal: (e.ClickCount == 2)
messageLabelClickTimer.Stop();
var player = new SoundPlayer(ExtraResource.bip_3short); // Double clicked signal
player.Play();
}
}
}
private void messageLabelClickTimer_Tick(object sender, EventArgs e)
{ // single-clicked
messageLabelClickTimer.Stop();
var player = new SoundPlayer(ExtraResource.bip_1short); // Single clicked signal
player.Play();
}
#endregion
My issue was with single/double-clicking rows in a DataGrid in WPF. For some reason the ButtonDown events weren't firing, only the OnMouseLeftButtonUp event was. Anyway, I wanted to handle the single-click differently from the double-click. It looks me a little time (I'm sure the solution isn't perfect, but it appears to work) to distill the problem down until I got it down to the below. I created a Task which calls an Action and that Action's target can be updated by a second click. Hope this helps someone!
private Action _clickAction;
private int _clickCount;
private void Grid_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("Button Click Occurred");
_clickCount++;
if (_clickCount == 1)
{
_clickAction = SingleClick;
}
if (_clickCount > 1)
{
_clickAction = DoubleClick;
}
if (_clickCount == 1)
{
Task.Delay(200)
.ContinueWith(t => _clickAction(), TaskScheduler.FromCurrentSynchronizationContext())
.ContinueWith(t => { _clickCount = 0; });
}
}
private void DoubleGridClick()
{
Debug.WriteLine("Double Click");
}
private void SingleGridClick()
{
Debug.WriteLine("Single Click");
}