What is the equivalent Following code in wpf
code in winapp :
private void textBox1_Leave(object sender, EventArgs e)
{
MessageBox.Show("www.stackoverflow.com");
}
private void textBox1_LostFocus(object sender, RoutedEventArgs e)
{
MessageBox.Show("www.stackoverflow.com");
}
(actually you could even reuse the same signature as before, all you need to do is hook the method to the LostFocus event instead of the Leave event)
Related
When button1 gets tapped by the stylus test method gets called twice, even though I am setting the Handled property in the stylusdown event. Is there a way to have the stylus event not propegate a secondary button click event?
namespace DialogTest
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
test(sender, e);
}
private void button1_StylusDown(object sender, StylusDownEventArgs e)
{
test(sender, e);
e.Handled = true;
}
private void test(object e, EventArgs env)
{
Console.WriteLine(e.ToString(), env.ToString());
Console.WriteLine("clicking");
}
}
If you look at this MSDN Input overview documentation. you will see the fact the both events are called.
From above link:
Because the stylus can act as a mouse, applications that support only mouse input can still obtain some level of stylus support automatically. When the stylus is used in such a manner, the application is given the opportunity to handle the appropriate stylus event and then handles the corresponding mouse event. In addition, higher-level services such as ink input are also available through the stylus device abstraction.
Since it does give you the order the events are called you can create a Boolean variable, set it in the StylusDown EventHandler, then check in your Button_Click EventHandler if it is true, set it to false then exit the Handler.
something like this.
public partial class Window1 : Window
{
bool StylusDown;
public Window1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
if(StylusDown)
{
StylusDown=false;
return;
}
test(sender, e);
}
private void button1_StylusDown(object sender, StylusDownEventArgs e)
{
StylusDown =true;
test(sender, e);
}
private void test(object e, EventArgs env)
{
Console.WriteLine(e.ToString(), env.ToString());
Console.WriteLine("clicking");
}
}
There may be a better way of accomplishing this, but this is was the first thing that came to mind.
MouseEventArgs has a property called StylusDevice that will be not null if the event originated from a stylus or touch event.
private void button1_Click(object sender, MouseButtonEventArgs e)
{
if (e.StylusDevice != null) return;
...
}
I've got a WPF application which contains a standard DataGrid showing a lot of data.
Now I want to add buttons to select the next/first/previous/last row.
Is there a way to tell the DataGrid to change the selection for me?
I tried to use
private void SelectNext_Click(object sender, RoutedEventArgs e)
{
datagrid.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
but it does not work for me (does not change the selected item, sets just the cell focus to the first item instead).
private void SelectNext_Click(object sender, RoutedEventArgs e)
{
if (dataGrid.Items.Count - 1 > datagrid.SelectedIndex)
{
datagrid.SelectedIndex++;
}
}
private void SelectPrevious_Click(object sender, RoutedEventArgs e)
{
if (dataGrid.SelectedIndex > 0)
{
datagrid.SelectedIndex--;
}
}
private void SelectFirst_Click(object sender, RoutedEventArgs e)
{
dataGrid.SelectedIndex = 0;
}
private void SelectLast_Click(object sender, RoutedEventArgs e)
{
dataGrid.SelectedIndex = dataGrid.Items.Count - 1;
}
If you fill your datagrid with a datasource by databinding, you can do that
Example of button "next"
private void btnNext_Click(object sender, RoutedEventArgs e)
{
ICollectionView view = CollectionViewSource.GetDefaultView(yourDataSource);
view.MoveCurrentToNext();
}
The interface ICollectionView has all the methods you need for moving the current item
In XAML remember also to set
<DataGrid ..... IsSynchronizedWithCurrentItem="True" >
In WPF, a button and a click event is:
<Button Click="Btn_Click" />
private void Btn_Click(object sender, RoutedEventArgs e)
{
....
}
In DevExpress, according to the documentation, I would guess the equivalent would be:
<dxb:BarButtonItem ItemClick="Btn_Click" />
private event ItemClickEventHandler Btn_Click(Item sender, RoutedEvent e)
{
....
}
But it is not compiling. I would guess it is very easy but I cannot find any example in the documentation.
The second parameter of the handler should be a ItemClickEventArgs:
private void Btn_Click(object sender, ItemClickEventArgs e)
{
....
}
How I can show or hide a groupbox from xaml.cs. I try to do this in the checkbox's event:
private void cbDaily_Checked(object sender, RoutedEventArgs e)
{
gbCalendar.Visibility = Visibility.Visible;
}
But this don't work.
It must be work on checked/unchecked events of checkbox like this way :
private void chkTest_Checked(object sender, RoutedEventArgs e)
{
grpTest.Visibility = System.Windows.Visibility.Visible;
}
private void chkTest_Unchecked(object sender, RoutedEventArgs e)
{
grpTest.Visibility = System.Windows.Visibility.Hidden;
}
It is working fine in my sample application. Can you please give more details of your problem, so I can have better idea. Is event fired properly ? Make sure name of groupbox in code behind is correct or not ?
What is the equivalent Following code in wpf
code in winapp :
private void textBox1_Enter(object sender, EventArgs e)
{
MessageBox.Show("www.stackoverflow.com");
}
There is no Enter event on a WPF textbox - you could use the GotFocus event to the same effect though.
private void textbox1_GotFocus(object sender, System.Windows.RoutedEventArgs e)
{
MessageBox.Show("www.stackoverflow.com");
}
this is accessed in the XAML as follows:
<TextBox GotFocus="textbox1_GotFocus"/>